13044 - Dynamic Stacks using Linked Lists   

Description

Define a stack node as

struct stacknode {
   int data;
   struct stacknode ∗next;
};


Implement the following four functions as shown in 13044.c:

  1. void push(struct stacknode **ptr2head, int elem);
    • Since the stack top has to be modified during pushing, we send a pointer to pointer to struct stacknode.
  2. int pop(struct stacknode **ptr2head);
    • We send a pointer to pointer to struct stacknode for the same reason.
    • After popping, you should return the memory of the popped element.
    • If the stack is empty and nothing can be popped, use  printf("stack is empty!\n");
  3. void show(struct stacknode *head);
    • Show all elements in the stack beginning with the top element.
    • If the stack is empty, use printf("empty stack\n");

The following must be included when submitting:

#include <stdio.h>
#include <stdlib.h>

struct stacknode {
   int data;
   struct stacknode *next;
};

/* Your Code Here. */

void function1(...)

void function2(...)

Input

Output

Sample Input  Download

Sample Output  Download

Partial Judge Code

13044.c

Partial Judge Header

13044.h

Tags




Discuss