Write menu driven program using 'C' for static implementation of stack.The Menu Includes -Push -Pop -Display


#include

#include

#define max 5

struct stack

{

int a[max];

int top;

};

void initstack(struct stack *ps);

int isfull(struct stack *ps);

int isempty(struct stack *ps);

void push(struct stack *ps);

int pop(struct stack *ps);

void display(struct stack *ps);

void main()

{

struct stack s;

int ch;

initstack(&s);

clrscr();

while(1)

{

printf("\n 1.Push.");

printf("\n 2.Pop.");

printf("\n 3.Display.");

printf("\n 4.Exit.");

printf("\n Enter Your Choice: ");

scanf("%d",&ch);

switch(ch)

{

case 1:

if(isfull(&s))

{

printf("\n Stack is Full.");

}

else

{

push(&s);

}

break;

case 2:

if(isempty(&s))

{

printf("\n Stack is Empty.");

}

else

{

printf("\n Popped Element is : %d",pop(&s));

}

break;

case 3:

if(isempty(&s))

{

printf("\n Stack is Empty.");

}

else

{

display(&s);

}

break;

case 4:

exit(0);

default:

printf("\n Invalid Choice.");

}

}

}

void initstack(struct stack *ps)

{

ps->top=-1;

}

int isempty(struct stack *ps)

{

if(ps->top==-1)

{

return (1);

}

else

{

return (0);

}

}

int isfull(struct stack *ps)

{

if(ps->top==max-1)

{

return (1);

}

else

{

return (0);

}

}

void push(struct stack *ps)

{

int ele;

printf("\n Enter The Element To Be Pushed: ");

scanf("%d",&ele);

ps->top++;

ps->a[ps->top]=ele;

}

int pop(struct stack *ps)

{

int ele;

ele=ps->a[ps->top];

ps->top--;

return(ele);

}

void display(struct stack *ps)

{

int i;

printf("\n Element in the Stack are: ");

for(i=0;i<=ps->top;i++)

{

printf("\t%d",ps->a[i]);

}

}


/*OUTPUT



 1.Push.

 2.Pop.

 3.Display.

 4.Exit.

 Enter Your Choice: 1


 Enter The Element To Be Pushed: 2


 1.Push.

 2.Pop.

 3.Display.

 4.Exit.

 Enter Your Choice: 1


 Enter The Element To Be Pushed: 8


 1.Push.

 2.Pop.

 3.Display.

 4.Exit.

 Enter The Element To Be Pushed: 5


 1.Push.

 2.Pop.

 3.Display.

 4.Exit.

 Enter Your Choice: 3


 Element in the Stack are:      2       8       5

 1.Push.

 2.Pop.

 3.Display.

 4.Exit.

 Enter Your Choice: 2


 Popped Element is : 5

 1.Push.

 2.Pop.

 3.Display.

 4.Exit.

  Enter Your Choice: 2


 Popped Element is : 8

 1.Push.

 2.Pop.

 3.Display.

 4.Exit.

 Enter Your Choice: 2


 Popped Element is : 2

 1.Push.

 2.Pop.

 3.Display.

 4.Exit.

 Enter Your Choice: 2


 Stack is Empty.

 1.Push.

 2.Pop.

 3.Display.

 4.Exit.

 Enter Your Choice:4 */
Write menu driven program using 'C' for static implementation of stack.The Menu Includes -Push -Pop -Display Write menu driven program using 'C' for static implementation of stack.The Menu Includes -Push -Pop -Display Reviewed by on November 16, 2013 Rating: 5
Powered by Blogger.