Stack
Posted by JanWan
Last Updated: March 03, 2012
  545

# include <stdio.h>
# include <ctype.h>
# include <conio.h>
# define MAXSIZE 200

int stack[MAXSIZE];
int top; // index pointing to the top of stack
void push(int);
int pop();

int main()   // MAIN
{
int will=1,i,num;
//clrscr();
while(will ==1)
{
printf("MAIN MENU:\n\t 1.Add element to stack\n\t 2.Delete element from the stack\n");
scanf("%d",&will);
switch(will)
{case 1:
printf("Enter the data...");
scanf("%d",&num);
push(num);
break;
case 2: i=pop();
printf("\t\nValue returned from pop function is %d\n",i);
break;
default:printf("Invalid Choice.");
}
printf("Do you want to do more operations on stack(1 for yes, any other key to exit):");
scanf("\n%d",&will);
}//end of outer while

} //end of main

void push(int y)  //starting of push operation
{
if(top>MAXSIZE)
{printf("STACK FULL");
return;
else
{
stack[top]=y;
top++;
}
}
int pop(int a) // starting of pop operation
{
if (top<=0)
{
printf("\tSTACK EMPTY");

return 0;
}
else
{
a=stack[top];
top--;
}
      getch();
return(a);
}

   
  
 
 
   

 
 
wrong heading.it's stack not sstck
 
Typo
 
Nice!