Question: #include #define MAXSIZE 20 struct Stack /* Structure definition for stack */ { int stk[MAXSIZE]; int top; }; struct Stack s; /* Function declarations/Prototypes */
#include #define MAXSIZE 20 struct Stack /* Structure definition for stack */ { int stk[MAXSIZE]; int top; }; struct Stack s; /* Function declarations/Prototypes */ void push (void); int pop(void); void display (void); void push8 (void); void push4 (void); void pop6 (void); void main () { int choice; int option = 1; s.top = -1; printf ("STACK OPERATION "); while (option) { printf ("------------------------------------------ "); printf (" 1 --> PUSH "); printf (" 2 --> POP "); printf (" 3 --> DISPLAY "); printf (" 4 --> EXIT "); printf (" 5--> push8 "); printf (" 6--> push4 "); printf (" 7--> pop6 "); printf ("------------------------------------------ "); printf ("Enter your choice "); scanf ("%d", &choice); switch (choice) { case 1: push (); break; case 2: pop (); break; case 3: display (); break; /*case 4: push8 ();*/ break; /*case 5: push4 ();*/ break; /*case 6: pop6 ();*/ break; case 7: return; } printf ("Do you want to continue (Type 0 or 1)? "); scanf ("%d", &option); } } /*Function to add an element to the stack*/ void push () { int num[8]={8,7,6,5,4,3,2,1}; if (s.top == (MAXSIZE - 1)) { printf ("Stack is Full "); return; } else { printf ("Enter the element to be pushed "); scanf ("%d", &num); s.top = s.top + 1; s.stk[s.top] = num; } return; } /*Function to delete an element from the stack*/ int pop () { int num; if (s.top == - 1) { printf ("Stack is Empty "); return (s.top); } else { num = s.stk[s.top]; printf ("poped element is = %d ", s.stk[s.top]); s.top = s.top - 1; } return(num); } /*Function to display the status of the stack*/ void display () { int i; if (s.top == -1) { printf ("Stack is empty "); return; } else { printf (" The status of the stack is "); for (i = s.top; i >= 0; i--) { printf ("%d ", s.stk[i]); } } printf (" "); }
6) Add the ability to PUSH an integer array called frame8 containing [8][7][6][5][4][3][2][1] when option 8 is selected. The element containing 1 should be at the top of the stack at the end of this operation. 7) Add the ability to PUSH an integer array called frame4 containing [12][11][10][9] when option 4 (re-defining it. Use 5 for Exit) is selected. The element containing 9 should be at the top of the stack at the end of this operation. 3) Add the ability to POP 6 elements off the stack when option 6 is selected. 6) Determine where changes need to be made in the code (prompts, switch statement, add 3 new functions: a) push8 b) push4 c) pop6