/* Stack using arrays*/
#include<stdio.h>
#define MAX 5
void push(int ele);
int pop();
void display();
int s[MAX];
int top=-1;
main()
{
int ch,ele;
clrscr();
while(1)
{
printf("1.Push \n2.Pop \n3.Display \n4.Exit\n");
printf("Enter your choice");
scanf("%d",&ch);
switch(ch)
{
case 1: printf("\nEnter ele to push");
scanf("%d",&ele);
push(ele);
break;
case 2: ele=pop();
printf("Poped Element is");
break;
case 3: printf("Elements in stack are");
display();
break;
case 4: exit();
}/*Switch case end*/
}/*While loop end*/
}/*main end*/
void push(int ele)
{
if(top==MAX-1)
{
printf("Stack overflow\n");
return;
}
else
{
top++;
s[top]=ele;
}
}
int pop()
{
if(top==-1)
{
printf("Stack Underflow\n");
return;
}
else
{
top--;
}
}
void display()
{
int i;
for(i=0;i<=top;i++)
printf("%d ",s[i]);
}
#include<stdio.h>
#define MAX 5
void push(int ele);
int pop();
void display();
int s[MAX];
int top=-1;
main()
{
int ch,ele;
clrscr();
while(1)
{
printf("1.Push \n2.Pop \n3.Display \n4.Exit\n");
printf("Enter your choice");
scanf("%d",&ch);
switch(ch)
{
case 1: printf("\nEnter ele to push");
scanf("%d",&ele);
push(ele);
break;
case 2: ele=pop();
printf("Poped Element is");
break;
case 3: printf("Elements in stack are");
display();
break;
case 4: exit();
}/*Switch case end*/
}/*While loop end*/
}/*main end*/
void push(int ele)
{
if(top==MAX-1)
{
printf("Stack overflow\n");
return;
}
else
{
top++;
s[top]=ele;
}
}
int pop()
{
if(top==-1)
{
printf("Stack Underflow\n");
return;
}
else
{
top--;
}
}
void display()
{
int i;
for(i=0;i<=top;i++)
printf("%d ",s[i]);
}
0 comments:
Post a Comment