fwfw
This commit is contained in:
parent
d0f10aa71d
commit
71064e4d39
@ -30,8 +30,10 @@ struct tree* read_tree(){
|
|||||||
if(!r) {
|
if(!r) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
r[strcspn(r, "\n")] = '\0';
|
buffer[strcspn(r, "\n")] = '\0';
|
||||||
assert(r);
|
if(buffer[0] == '\0'){
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
struct tree* node = calloc(1,sizeof(struct tree));
|
struct tree* node = calloc(1,sizeof(struct tree));
|
||||||
memcpy(node->value,buffer,SIZE);
|
memcpy(node->value,buffer,SIZE);
|
||||||
if(buffer[0] == '*'){
|
if(buffer[0] == '*'){
|
||||||
@ -42,9 +44,6 @@ struct tree* read_tree(){
|
|||||||
}
|
}
|
||||||
node->left = read_tree();
|
node->left = read_tree();
|
||||||
node->right = read_tree();
|
node->right = read_tree();
|
||||||
// Ak je nacitany riadok listovy uzol ,tak netreba robit nic
|
|
||||||
// inak rekurzivne nacitanie laveho syna
|
|
||||||
// a rekurzivne nacitanie praveho syna
|
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
void print_tree(struct tree* tree,int offset){
|
void print_tree(struct tree* tree,int offset){
|
||||||
@ -78,8 +77,9 @@ int main(void){
|
|||||||
char line[SIZE];
|
char line[SIZE];
|
||||||
|
|
||||||
|
|
||||||
while( fgets(line, sizeof(line), stdin)){
|
while( fgets(line, sizeof(line), stdin)){
|
||||||
if(strcmp(line, "\n") == 0){
|
line[strcspn(line, "\n")] = '\0';
|
||||||
|
if(line[0] == '\0'){
|
||||||
whitespace = true;
|
whitespace = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -87,6 +87,7 @@ int main(void){
|
|||||||
}
|
}
|
||||||
int numOfLeaves = count_leaves(tree);
|
int numOfLeaves = count_leaves(tree);
|
||||||
char answer[SIZE];
|
char answer[SIZE];
|
||||||
|
bool exs = false;
|
||||||
printf("Expert z bufetu to vie.\n");
|
printf("Expert z bufetu to vie.\n");
|
||||||
if(!tree || !whitespace){
|
if(!tree || !whitespace){
|
||||||
printf("Chybna databaza\n");
|
printf("Chybna databaza\n");
|
||||||
@ -97,12 +98,12 @@ int main(void){
|
|||||||
printf("Odpovedajte 'a' pre prvu moznost alebo 'n' pre druhu moznost.");
|
printf("Odpovedajte 'a' pre prvu moznost alebo 'n' pre druhu moznost.");
|
||||||
while(tree){
|
while(tree){
|
||||||
printf("\n%s", tree->value);
|
printf("\n%s", tree->value);
|
||||||
if( fgets(answer, sizeof(answer), stdin)){
|
fgets(answer, sizeof(answer), stdin);
|
||||||
|
answer[strcspn(answer, "\n")] = '\0';
|
||||||
|
if(answer[0] == '\0'){
|
||||||
printf("\nKoniec vstupu\n");
|
printf("\nKoniec vstupu\n");
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
answer[strcspn(answer, "\n")] = '\0';
|
|
||||||
|
|
||||||
if(strcmp(answer, "n") == 0){
|
if(strcmp(answer, "n") == 0){
|
||||||
tree = tree->right;
|
tree = tree->right;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user