nix
Senior Member
Code:
/*stack program*/
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
int s[10],top=-1,item,n=5;
void push()
{
if (top==n-1)
{
printf("stack is full, so pushing not possible\n");
getch();
return;
}
printf("ener the item to be pushed\n");
scanf("%d",&item);
top=top+1;
s[top]=item;
}
void pop()
{
if (top==-1)
{
printf("stack is emptly so popping not possible\n");
getch();
return;
}
item=s[top];
printf("the popped element is %d\n",item);
top=top-1;
}
void display()
{
int i;
{
if (top==-1)
{
printf("stack is empty, so display not possible\n");
getch();
return;
}
for (i=top;i>=0;i--)
{
printf("%d\n",s[i]);
}
}
}
void main()
{
int choice;
clrscr();
for (;;)
{
printf("1....push\n");
printf("2....pop\n");
printf("3....display\n");
printf("4....exit\n");
printf("enter the choice\n");
scanf("%d",&choice);
switch(choice)
{
case 1:push();
break;
case 2:pop();
break;
case 3:display();
break;
default:exit(0);
}
}
getch();
}
edit: any helpful links to where i can find codes for C programs? ( i'm in 3rd sem engg)