answersLogoWhite

0

/* 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

12y ago

What else can I help you with?

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 009-71 test rig?

The 009-71 test rig is a specialized apparatus used primarily for evaluating and testing hydraulic systems and components. It simulates various operational conditions to assess the performance, reliability, and durability of hydraulic equipment. Typically employed in industrial and research settings, the rig allows engineers to conduct controlled experiments and gather data for analysis. Its design may vary depending on the specific testing requirements and the components being evaluated.