buffet
This commit is contained in:
parent
c4c808544f
commit
c88245fafd
@ -10,7 +10,8 @@ struct tree {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
struct tree* read_tree(){
|
struct tree* read_tree(int* counter){
|
||||||
|
int* c = counter;
|
||||||
char buffer[50];
|
char buffer[50];
|
||||||
memset(buffer,0,50);
|
memset(buffer,0,50);
|
||||||
char* r = fgets(buffer,50,stdin);
|
char* r = fgets(buffer,50,stdin);
|
||||||
@ -25,6 +26,8 @@ struct tree* read_tree(){
|
|||||||
if(buffer[0] != '\0'){
|
if(buffer[0] != '\0'){
|
||||||
struct tree* node = calloc(1,sizeof(struct tree));
|
struct tree* node = calloc(1,sizeof(struct tree));
|
||||||
memcpy(node->value, buffer,50);
|
memcpy(node->value, buffer,50);
|
||||||
|
*c += 1;
|
||||||
|
counter = &c;
|
||||||
if(buffer[0] != '*'){
|
if(buffer[0] != '*'){
|
||||||
if(node->left == NULL){
|
if(node->left == NULL){
|
||||||
node->left = read_tree();
|
node->left = read_tree();
|
||||||
@ -33,6 +36,20 @@ struct tree* read_tree(){
|
|||||||
node->right = read_tree();
|
node->right = read_tree();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if(node->left != NULL && node->right != NULL){
|
||||||
|
*c -= 2;
|
||||||
|
counter = &c;
|
||||||
|
}
|
||||||
|
if(c == 1){
|
||||||
|
r = fgets(buffer,50, stdin);
|
||||||
|
//int x = strlen(buffer);
|
||||||
|
// buffer[x-1]='\0';
|
||||||
|
if(buffer[0] != '\n'){
|
||||||
|
printf("Chybna databaza\n");
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -139,8 +156,8 @@ int main(){
|
|||||||
printf("Expert z bufetu to vie.\n");
|
printf("Expert z bufetu to vie.\n");
|
||||||
|
|
||||||
struct tree* tree = NULL;
|
struct tree* tree = NULL;
|
||||||
|
int counter;
|
||||||
tree = read_tree();
|
tree = read_tree(&counter);
|
||||||
int count = count_leaves(tree);
|
int count = count_leaves(tree);
|
||||||
|
|
||||||
printf("Pozna %d druhov ovocia a zeleniny.\n", count);
|
printf("Pozna %d druhov ovocia a zeleniny.\n", count);
|
||||||
|
Loading…
Reference in New Issue
Block a user