Question: Write C programs stack.h, stack.c to implement the stack data structure by a linked list. stack.h and stack.c contain the following. definition of stack node

Write C programs stack.h, stack.c to implement the stack data structure by a linked list. stack.h and stack.c contain the following.

  1. definition of stack node structure SNODE with int data and next pointer.
  2. void push(SNODE **topp, int value); this creates a node and set data to value and push to top of the stack.
  3. void pop(SNODE **topp); this pop up the top element.
  4. int peek(SNODE *top); this returns the data of front node.
  5. void clean(SNODE **topp); this clean up the stack.
  6. Write your main function program a6q3.c to test the above functions. For example using a6q3.c to test, it should have the following output.

a6q3

#include "stack.h" int main(int argc, char* args[]) { SNODE *top = NULL; int i=0; for (i=1; i<=12; i++) { push(&top, i); } printf("%d ", peek(top)); pop(&top); printf("%d ", peek(top)); printf(" "); while (top != NULL) { printf("%d ", peek(top)); pop(&top); } for (i=1; i<=12; i++) { push(&top, i); } clean(&top); while (top != NULL) { printf("%d ", peek(top)); pop(&top); } return 0; }

stack.h

#ifndef STACK_H #define STACK_H #include  #include  #include  #include  typedef struct node { int data; struct node *next; } SNODE; void push(SNODE **topp, int value); void pop(SNODE **topp); int peek(SNODE *); void clean(SNODE **topp); #endif

stack.c

#include "stack.h" void push(SNODE **topp, int value) { // your code } void pop(SNODE **topp) { // your code } int peek(SNODE *top) { // your code } void clean(SNODE **topp) { // your code }

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!