Professional Documents
Culture Documents
Code:
/* Write a C program to implement stack. Stack is a LIFO data strcuture *
* LIFO - Last in First Out
struct stack
{
int stk[MAXSIZE];
int top;
};
/* Function declaration/Prototype*/
void main ()
{
int choice;
int option = 1;
clrscr ();
s.top = -1;
-->
PUSH
\n");
printf ("
-->
POP
\n");
printf ("
-->
DISPLAY
printf ("
-->
EXIT
printf ("------------------------------------------\n");
("%d", &choice);
switch (choice)
{
case 1: push();
break;
\n");
\n");
case 2: pop();
break;
case 3: display();
break;
case 4: return;
}
fflush (stdin);
printf ("Do you want to continue(Type 0 or 1)?\n");
scanf
("%d", &option);
}
}
/*--------------------------------------------------------------------------Output
STACK OPERATION
------------------------------------------
1
2
-->
-->
3
4
PUSH
POP
-->
-->
DISPLAY
EXIT
-->
-->
3
4
PUSH
POP
-->
-->
DISPLAY
EXIT
-->
PUSH
-->
POP
3
-->
-->
DISPLAY
EXIT
-->
PUSH
-->
POP
3
4
-->
-->
DISPLAY
EXIT
1
-----------------------------------------1
-->
2
PUSH
-->
POP
-->
DISPLAY
-->
EXIT
-->
2
PUSH
-->
POP
-->
DISPLAY
-->
EXIT