answersLogoWhite

0


Best Answer

/* C program to implement stack. Stack is a LIFO data strcuture LIFO - Last in First Out Perform PUSH(insert operation), POP(Delete operation) and Display stack */

#include

#include

#define MAXSIZE 5

struct stack /* Structure definition for stack */

{

int stk[MAXSIZE];

int top;

};

typedef struct stack STACK;

STACK s;

/* Function declaration/Prototype*/

void push (void);

int pop(void);

void display (void);

void main ()

{

int choice;

int option = 1;

clrscr ();

s.top = -1;

printf ("STACK OPERATION\n");

while (option)

{

printf ("--------------\n");

printf (" 1 -> PUSH \n");

printf (" 2 -> POP \n");

printf (" 3 -> DISPLAY \n");

printf (" 4 -> EXIT \n");

printf ("--------------\n");

printf ("Enter your choice\n");

scanf ("%d", &choice);

switch (choice)

{

case 1: push();

break;

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);

}

}

/*Function to add an element to the stack*/

void push ()

{

int num;

if (s.top -1)

{

printf ("Stack is empty\n");

return;

}

else

{

printf ("\nThe status of the stack is\n");

for (i = s.top; i >= 0; i-)

{

printf ("%d\n", s.stk[i]);

}

}

printf ("\n");

}

by

ankit shukla

User Avatar

Wiki User

11y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Implement a class stack which simulates the operations of the stack allowing LIFO operationsAlso implement push and pop operations for the stack?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

What is a mini stair stepper used for?

A mini stair stepper is a workout machine that simulates climbing stairs. It contains two platforms, one for each foot, and they alternate in going up and down when a person is pushing them down.


Define prototype in ooad?

prototyping is an approach to e development to a system where software simulates the aspects of an actual processing system, in simple words prototyping can be called as a shorter version of working system, thanks Bharat Kumar Mishra bharat9234@yahoo.com


How do you calculate maximum surge current?

this is below the point where components are destroyed the easy way is to submit a couple dozen samples to ul laboratories they have equipment that simulates the surge currents they merely destroy a dozen see what the current was to destroy them then average it deduct 10% and see if the remaining samples arent destroyed


What are preventive measures of defective emergency lights?

Preventive maintenance procedures to use on emergency light packs is to test the fixture once a week. There is a test button on the side of the fixture that simulates a power failure. Most emergence light packs now have sealed battery to power their units. In old wet cell battery fixtures check the liquid levels in the batteries. Check the electrolyte strength and top up with water if the fluid level is low.


What is a reservoir engineer And what do they do?

A reservoir engineer simulates a model of a real oil field and thus determines basic parameters of the reservoir which helps as guidelines for a drilling engineer to drill a well on a particular location. Reservoir engineer has to analyse a well throughout it's life hence it also ties up with a production engineer to suggest him ways how to extract the oil lying underneath the formation. There are several other roles which a reservoir engineer plays and thus serves as one of the major pillars of the Petroleum Industry.