/*operations performed on stack*/

#include<stdio.h>
#include<conio.h>
#define MAXSIZE 10
void push();
int pop();
void traverse();
int stack[MAXSIZE];
int Top=-1;
void main()
{
int choice;
char ch;
do
{
clrscr();
printf("\n1. PUSH ");
printf("\n2. POP ");
printf("\n3. TRAVERSE ");
printf("\nEnter your choice");
scanf("%d",&choice);
switch(choice)
{
case 1: push();
break;
case 2: printf("\nThe deleted element is %d",pop());
break;
case 3: traverse();
break;
default: printf("\nYou Entered Wrong Choice");
}
printf("\nDo You Wish To Continue (Y/N)");
fflush(stdin);
scanf("%c",&ch);
}
while(ch=='Y' || ch=='y');
}

void push()
{
int item;
if(Top == MAXSIZE - 1)
{
printf("\nThe Stack Is Full");
getch();
exit(0);
}
else
{
printf("Enter the element to be inserted");
scanf("%d",&item);
Top= Top+1;
stack[Top] = item;
}
}

int pop()
{
int item;
if(Top == -1)
{
printf("The stack is Empty");
getch();
exit(0);
}
else
{
item = stack[Top];
Top = Top-1;
}
return(item);
}

void traverse()
{
int i;
if(Top == -1)
{
printf("The Stack is Empty");
getch();
exit(0);
}
else
{
for(i=Top;i>=0;i--)
{
printf("Traverse the element");
printf("\n%d",stack[i]);
}
}
}

/*output of the program*/
1. PUSH
2. POP
3. TRAVERSE
Enter your choice
1
eneter the to be inserted
2
do you want to contniue(y/n)
y

1. PUSH
2. POP
3. TRAVERSE
Enter your choice
2
the deleted elment is
2

do you want to contniue(y/n)
n

 

Home       |      About Us       |     Portfolio       |      Services       |       Career        |    Contact Us       |      Industrial Training        |      Achievement 
   

Program to demonstrate the operation performed on stack.

 

 

 

 

 

 

 

 

 

                                                                                                                                          

1 Program to demonstrate the operation performed on stack.
2 Program to demonstrate the linked implementations of stacks.
3 Program to input infix expression and convert it into an equivalent postfix expression.
4 Program to convert infix expression to prefix and postfix from using stack.
5 Program to accept a postfix expression ask the values for variables of the expression by the uses and then calculate the expression for that values.

 

     
Home       |      About Us       |     Portfolio       |      Services       |       Career        |    Contact Us       |      Industrial Training        |      Achievement