CLASS NOTES FOR 9/26/02 Stack = Last one first ADT = abstract data type (user defined data type) Info is hidden when things are abstract. for (int i = 0, i < 6, i++) cin >> table[i]; for (i=5,i >= 0 , i--) Everything is a character (every strike on a keyboard is a character) Assume the following: 23 char t; cin.get (t) cout <, t //will give u the value 2 void main() { int num; char t; cin.get(t) if t(>=¡¯0¡¯) && (t<=¡¯9¡¯){ cin >> num; cout << ¡°number¡±; else cout << ¡°not number¡±; // output = 3 ENTER A POSTFIX NOTATION //ENTER A POSTFIX NOTATION #include void push (int stack[],int &top,int x){ stack[top++]=x; }//push int pop (int stack [],int &top){ return stack [--top]; }//pop int evaluate(int num1, int num2, char t){ switch(t){ case'+':return num2+num1;break; case'-':return num2-num1;break; case'/':return num2/num1;break; case'*':return num2*num1;break; }//switch }//evaluate int main (){ int stack [10],top=0,x,num1,num2,value; char t; cout<<"please enter a postfix notation"<='0')&&(t<='9')){ cin.putback(t);cin>>x; push(stack,top,x);}//if else if ((t=='+') || (t=='-')||(t=='/')||(t=='*')){ num1=pop(stack,top); num2=pop(stack,top); value=evaluate (num1,num2,t); push (stack,top,value); }//else if if (t=='\n') break; }//while cout< 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"<