Question: help me to write c code Stack Medium AC Ratio: 14.4% (318/2207) #Pointers #Struct Loop #lf/else Stack is an abstract data type that serves as

 help me to write c code Stack Medium AC Ratio: 14.4%(318/2207) #Pointers #Struct Loop #lf/else Stack is an abstract data type thatserves as a collection of elements, with two main principal operations: 1.Push: which adds an element to the top of the stack 2.

help me to write c code

Stack Medium AC Ratio: 14.4% (318/2207) #Pointers #Struct Loop #lf/else Stack is an abstract data type that serves as a collection of elements, with two main principal operations: 1. Push: which adds an element to the top of the stack 2. Pop: which removes an element from the top of the stack if the stack is not empty Data Element Data Data Element Last In - First Out Push Pop Data Element Data Element Data Element Data Element Data Element Data Element Data Element Data Element Data Element Data Element Stack Stack Please implement push and pop operations of the stack using linked list. Loader Your code will be verified by the main file below Binclude include Binclude // elements of the stack struct element int data; struct element ext; ): 1/ point to the next element in the stack struct head int size: struct element ext; struct element tep! ): 1/ record the size of the stack // point to the bottom element in the stack if there is any // point to the top of the stack void print_stack(struct head stack p): void push(struct head stack p, int data); struct element "pop(struct head stack p): // put an element to the top of the stack Il remove an element from the top of the stack int main(void) // stack declaration struct head stack head; stack head.size - stack_head.next = NULL; stack_head.top - NULL; 11 read instructions int nun, data: char command[5]: scanf("%d", Snum): for (int i -e; i next; ptr I- NULL; ptr - ptr-text) printf("%d". ptr->data): 17 Your code goes here INPUT AND OUTPUT EXAMPLE Input The input contains two parts. The first part is the number of the operations. The second part contains the content of the operations, which is push or pop an integer to/from the stack Output The output contains two lines. The first line is the size of the stack, and the second Ine consists of elements date and each date la followed by a space. You should output them in chronological order. #include ude #include #include UPLOAD FILE UPLOAD FROM GITHUB A UPLOAD FROM GITLAB // create an element and push it to the top of the stack 3 struct element { 11 elements of the stack int data; struct element *next; // point to the next element in the stack }; 1 void push(struct head *stack_P, int data) { 2} 3 4 struct elements pop(struct head *stack_p) { 5} // return the element which is popped from the stack struct head { int size; // record the size of the stack struct element *next; // point to the bottom element in the stack if there is any struct element *top; // point to the top of the stack }; void print_stack(struct head *stack_p); void push(struct head *stack_p, int data); struct element *pop(struct head *stack_p); Il put an element to the top of the stack Il remove an element from the top of the stack int main(void) { 1/ stack declaration struct head stack_head; stack_head.size = @; stack_head.next = NULL; stack_head.top = NULL; // read instructions int num, data; char command[5]; scanf("%d", &num); for (int i = @; i size); for (struct element *ptr = stack_p->next; ptr != NULL; ptr = ptr->next) printf("%d ", ptr->data); } 1/ Your code goes here Input Output 1 5 push 1 push 2 push 3 pop pop Sample 2 Input Output 1 5 push 1 2 pop push 2 push 3 pop

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!