CLASS NOTES FOR 9/17/02 Stack Queue Tree Graph Searching Sorting 1) Which of the following program is better? a) cout<<ĦħEnter Your NameĦħ; char name [15] cin>>name; int age cin>> age; float salary OR b) cout<<ĦħEnter your NameĦħ; struct person cin>>employee.name; { cin>>employee.age; char name [15] int age float salary } person employee Choice b is a better form of programming because it has structure to it. Infix Evaluation 2 3 4 * + Algorithm = If digit then PUSH else if operator pop pop evaluate push else no more, pop DISPLAY How would make a stack? Array 176 786 664 0 1 2 3 Stack number [0] = 176 number [1] = 786 number [2] = 664 number [i] i++; stack [i] i++; change i to top stack[top] = X top++; 1) Write a function called Push? Int stack [10]; Int top = 0; Int x; Push (){ Stack [top] = x Top++; } main() { push(); }//main 2) 2 ways to use stack are Array and Pointer SIMPLE STACK MENU #include void push (int mystack[],int & mytop,int item){ mystack[mytop]=item; mytop=mytop+1;} //PUSH int pop(int mystack[],int &mytop){ mytop=mytop-1; int item=mystack[mytop]; return item; }//POP int isempty(int mytop){ if(mytop==0) return 1; else return 0;}//ISEMPTY int isfull(int mytop,const int MAXSTACKSIZE){ if(mytop==MAXSTACKSIZE)return 1; else return 0;}//ISFULL void main(){ const int MAXSTACKSIZE=5; int mystack[MAXSTACKSIZE];int mytop,x,option; mytop=0;//STACK TOP INITILIZATION do{cout<<"SELECT ONE OF THE FOLLOWING OPTIONS:"<>option; switch(option){ case 1: if (isfull(mytop,MAXSTACKSIZE)) cout<<"YOU CANT PUSH"<>x; push(mystack,mytop,x);}//ELSE break; case 2: if(isempty(mytop)) cout<<"YOU CANT POP"<