#include <iostream>
#include <queue>
using namespace std;
struct Node{
int data;
struct Node* left, *right;
};
// Function to count the full Nodes in a binary tree
int fullcount(struct Node* node){
// Check if tree is empty
if (!node){
return 0;
}
queue<Node *> myqueue;
// traverse using level order traversing
int result = 0;
myqueue.push(node);
while (!myqueue.empty()){
struct Node *temp = myqueue.front();
myqueue.pop();
if (temp->left && temp->right){
result++;
}
if (temp->left != NULL){
myqueue.push(temp->left);
}
if (temp->right != NULL){
myqueue.push(temp->right);
}
}
return result;
}
struct Node* newNode(int data){
struct Node* node = new Node;
node->data = data;
node->left = node->right = NULL;
return (node);
}
int main(void){
struct Node *root = newNode(10);
root->left = newNode(20);
root->right = newNode(30);
root->left->left = newNode(40);
root->left->right = newNode(50);
root->left->left->right = newNode(60);
root->left->right->right = newNode(70);
cout <<"count is: "<<fullcount(root);
return 0;
}
#include <iostream>
using namespace std;
int main(){
int k,n,m;
cout<<"Introduceti numar n:";
cin>>n;
cout<<"Introduceti numar k:";
cin>>k;
//daca restul impartirii lui n la k
//este mai mic decat jumatate din impartitor
if(n%k<=k/2){
//atunci multiplul este cel mai mare multiplu mai mic decat n
m=k*(n/k);
}
else{
//altfel este cel mai mic multiplu mai mare decat n
m=k*(n/k+1);
}
cout<<"Multiplu "<<k<<" cel mai apropriat de "<<n<<" este "<<m;
return 0;
}
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct _tree
{ char v[18];
int len, index, plus_l, plus_r;
struct _tree *l, *r;
} Tree;
void Ins(Tree **t, char *val, int val_len, int indeks)
{ if(!(*t))
{ *t = (Tree*)malloc(sizeof(Tree));
strcpy((*t)->v, val);
(*t)->len = val_len;
(*t)->index = indeks;
(*t)->plus_l = (*t)->plus_r = 0;
(*t)->l = (*t)->r = NULL;
}
else if(((*t)->len > val_len) || (((*t)->len == val_len) && (strcmp((*t)->v, val) > 0)))
{ if((*t)->r) Ins(&(*t)->r, val, val_len, 1);
else
{ Ins(&(*t)->r, val, val_len, (*t)->index + 1);
(*t)->plus_r = 0;
}
}
else
{ (*t)->index += 1;
(*t)->plus_r += 1;
if((*t)->l) Ins(&(*t)->l, val, val_len, 1);
else
{ Ins(&(*t)->l, val, val_len, (*t)->index - 1);
(*t)->plus_l = 0;
}
}
}
int Find(Tree **t, char *val, int val_len)
{ if(*t)
{ if(strcmp((*t)->v, val) == 0)
{ printf("%d
", (*t)->index);
return 1;
}
else if(((*t)->len > val_len) || (((*t)->len == val_len) && (strcmp((*t)->v, val) > 0)))
{ if((*t)->plus_r)
{ if((*t)->r)
{ int t_plus_r = (*t)->plus_r;
(*t)->r->index += t_plus_r;
(*t)->r->plus_l += t_plus_r;
(*t)->r->plus_r += t_plus_r;
}
(*t)->plus_r = 0;
}
return Find(&(*t)->r, val, val_len);
}
else
{ if((*t)->plus_l)
{ if((*t)->l)
{ int t_plus_l = (*t)->plus_l;
(*t)->l->index += t_plus_l;
(*t)->l->plus_l += t_plus_l;
(*t)->l->plus_r += t_plus_l;
}
(*t)->plus_l = 0;
}
return Find(&(*t)->l, val, val_len);
}
}
else return 0;
}
int main()
{ int T, cmd, len;
scanf("%d", &T);
Tree *t = NULL;
char val[18];
while(T--)
{ scanf("%d %s", &cmd, val);
len = strlen(val);
if(cmd == 1) Ins(&t, val, len, 1);
else if(!Find(&t, val, len)) printf("Data tidak ada
");
}
return 0;
}
#include <stdio.h>
#include <stdlib.h>
int main (void){
int vetor [2];
int *v; // ponteiro
v = vetor;
v[0] = 123;
v[1] = 456;
printf ("vetor[0] = %d
", vetor[0]);
printf ("vetor[1] = %d
", vetor[1]);
system ("pause");
}