Friday, August 28, 2009

Stack Implementation



#include<stdio.h>



#include<conio.h>



void
main()



{




int
s[100],i=0,m,j;




int
n;




char
ans;



clrscr();




do




{




clrscr();




printf("\n\t\t\tSTACK");




printf("\n\t\t\t*****");




printf("\nMENU");




printf("\n====");




printf("\n\t1.PUSH");




printf("\n\t2.POP");




printf("\n\t3.SHOW");




printf("\n\t4.EXIT");




printf("\n\n ENTER THE CHOICE:->");




scanf("%d",&n);




switch(n)




{





case
1:




printf("\nENTER THE
ELEMENT:->"
);




scanf("%d",&m);




i++;




s[i]=m;




if(s[i]>100)




printf("STACK IS FULL");




else




printf("\nTHE PUSHED
ELEMENT IS:->%d"
,s[i]);




break;





case
2:




if(s[i]<1)




printf("\nSTACK IS EMPTY");




else




{




printf("\n
THE POPED ELEMENT IS :->%d"
,s[i]);




i--;




}




break;





case
3:




printf("\nSTACK ELEMENTS
ARE "
);




for(j=1;j<=i;j++)




printf("\n\t\t%d",s[j]);




break;





case
4:




exit();




break;




}




printf("\n\n DO U CONTINUE(Y/N):->");




scanf("%s",&ans);



}




while
(ans=='Y' || ans=='y');



getch();



}





No comments:

Post a Comment