Answered step by step
Verified Expert Solution
Link Copied!

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.

  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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Multidimensional Array Data Management In Databases

Authors: Florin Rusu

1st Edition

1638281483, 978-1638281481

Students also viewed these Databases questions

Question

explain what is meant by experiential learning

Answered: 1 week ago

Question

identify the main ways in which you learn

Answered: 1 week ago