Академический Документы
Профессиональный Документы
Культура Документы
Plate trays
Pile of books
Representation of STACK
PUSH
6
5
TOP
PO
P
Characteristics of stacks
1.Stack is an ordered list with the restriction that
insertion or deletions are done only at the top of
the stack.
2.Whenever a new element is inserted older
element moves down one position.
3.Stack is based on LIFO (Last In First Out) .
IMPLEMENTATION OF STACKS
1.By using ARRAYS.
2.By using Linked Lists
main()
{
struct stack*s;
int n,ch,x;
printf("enter the capacity of stack\n");
scanf("%d",&n);
s=create(n);
while(1)
{
printf("1.push\t2.pop\t3.display\t4.exit\n");
printf("enter your choice\n");
scanf("%d",&ch);
switch(ch)
{
case 1:printf("enter the element to be insert\n");
scanf("%d",&x);
push(s,x);
printf("elements after insertion acre\n");
display(s);
break;
case 2:pop(s);
printf("elements after deleting are\n");
display(s);
break;
case 3:display(s);
break;
case 4:exit(0);
break;
}
}
}
main()
{
struct stack*s=NULL;
int x,ch;
while(1)
{
printf("\n1.push\t2.pop\t3.display\t4.e
xit");
printf("\nenter your choice\n");
scanf("%d",&ch);
switch(ch)
{
case 1:
printf("enter the element to
insert\n");
scanf("%d",&x);
s=push(s,x);
display(s);
break;
case 2:
s=pop(s);
display(s);
break;
case 3:
display(s);
break;
case 4:exit(0);
break;
}
}
}
Applications Of Stacks
1.Conversion of infix to postfix
expression.
2.Conversion of infix to prefix
expression.
3.Evaluation of postfix expression.
4.Paranthesis matching.
5.Recursion.