Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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.
- definition of stack node structure SNODE with int data and next pointer.
- void push(SNODE **topp, int value); this creates a node and set data to value and push to top of the stack.
- void pop(SNODE **topp); this pop up the top element.
- int peek(SNODE *top); this returns the data of front node.
- void clean(SNODE **topp); this clean up the stack.
- 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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started