Home > Back-end >  Menu after each input instructions are written for help, start over
Menu after each input instructions are written for help, start over

Time:05-03

This is a binary tree menu operation, C
Int main ()
{
BiTree T;
Int x, y;
While (1)
{
Printf (" -- -- -- -- -- -- -- -- -- -- -- -- -- operating option -- -- -- -- -- -- -- -- -- -- - \ n ");
Printf (" \ n 1: start program ");
Printf (" \ n 2: create tree ");
Printf (" 3: first sequence traversal \ n ");
Printf (" 4: sequence traversal (recursive) \ n ");
Printf (" 5: sequence traversal (non-recursive) \ n ");
Printf (" after 6: sequence traversal \ n ");
Printf (" exit 0: \ n ");
Printf (" -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- \ n ");

Printf (" please start programs: ");
The scanf (" % d ", & amp; X);
printf("\n");

If (x==0)
break;

The switch (x)
{case 1:
{y=c ();
The switch (y)
{
Case 2: CreateBiTree (& amp; T); printf("\n"); Y=c (); break;
Case 3: printf (" sequence traversal is first: "); The pre (T); printf("\n"); Y=c (); break;
Case 4: printf (" sequence traversal (recursive) : "); In (T); printf("\n"); Y=c (); break;
Case 5: printf (" sequence traversal (non-recursive) : "); Inorder (T); printf("\n"); Y=c (); break;
Case 6: printf (" after sequence traversal is: "); Post (T); printf("\n"); Y=c (); break;
Default:
Printf (" please enter again \ n "); Y=c ();
}
}
Default:
Printf (" please enter again \ n ");
}
}
}
Input 1, 2, after the sequence, to start over again lose 1, and then lose what I want, how can I lost just one at a time, and then directly to lose every time I want instructions

CodePudding user response:

Y=c (); Guess the c () function is a choice function, the return value 0 to 6 or some other number, assuming that contains 0 (can also be a 2-6 Numbers), such a change, for reference:
 # include 

Int main ()
{
BiTree T;
Int x, y;
While (1)
{
Printf (" -- -- -- -- -- -- -- -- -- -- -- -- -- operating option -- -- -- -- -- -- -- -- -- -- - \ n ");
Printf (" \ n 1: start program ");
Printf (" \ n 2: create tree ");
Printf (" 3: first sequence traversal \ n ");
Printf (" 4: sequence traversal (recursive) \ n ");
Printf (" 5: sequence traversal (non-recursive) \ n ");
Printf (" after 6: sequence traversal \ n ");
Printf (" exit 0: \ n ");
Printf (" -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- \ n ");

Printf (" please start programs: ");
The scanf (" % d ", & amp; X);
printf("\n");

While (x==1) {
Y=c ();
The switch (y)
{
Case: 0 x=0; break;
Case 2: CreateBiTree (& amp; T); printf("\n"); break;//y=c ();
Case 3: printf (" sequence traversal is first: "); The pre (T); printf("\n"); break;//y=c ();
Case 4: printf (" sequence traversal (recursive) : "); In (T); printf("\n"); break;//y=c ();
Case 5: printf (" sequence traversal (non-recursive) : "); Inorder (T); printf("\n"); break;//y=c ();
Case 6: printf (" after sequence traversal is: "); Post (T); printf("\n"); break;//y=c ();
Default:
Printf (" 2: please enter again \ n "); break;//y=c ();
}
}
If (x==0) break;
}
}
  • Related