Commit 915320d

mo khan <mo.khan@gmail.com>
2020-07-05 17:55:53
Create program to showcase a min stack
1 parent 080c0e2
src/01/06/main.c
@@ -1,8 +1,35 @@
+#include "min_stack.h"
 #include <stdio.h>
 #include <stdlib.h>
 
+void inspect(Stack *stack)
+{
+  Node *head = stack->head;
+
+  while(head) {
+    printf("\t [%7d]\n", head->data);
+    head = head->next;
+  }
+}
+
 int main(int argc, char *argv[])
 {
-  printf("=== COMP-272 - Assignment 1 - Question 1b ===\n");
+  printf("=== COMP-272 - Assignment 1 - Question 6 ===\n");
+
+  Stack *stack = initialize();
+
+  for (int i = 0; i < 10; i++) {
+    int data = rand() % 100;
+    printf("Push: %d\n", data);
+    push(stack, data);
+    inspect(stack);
+  }
+
+  while(size(stack) > 0) {
+    printf("Pop: %d\n", pop(stack));
+    inspect(stack);
+  }
+
+  free(stack);
   return 0;
 }
src/01/06/min_stack.c
@@ -2,7 +2,7 @@
 #include <stdlib.h>
 #include "min_stack.h"
 
-Stack *initialize() {
+Stack *initialize(void) {
   Stack *self = malloc(sizeof(Stack));
   self->head = NULL;
   return self;
src/01/06/min_stack.h
@@ -9,7 +9,7 @@ typedef struct {
   Node *head;
 } Stack;
 
-Stack *initialize();
+Stack *initialize(void);
 void push(Stack *self, int data);
 int pop(Stack *self);
 int size(Stack *self);
src/01/06/README.md
@@ -3,14 +3,14 @@
 Name: Mo Khan
 Student ID: 3431709
 
-1. Problem Statement:
+## Problem Statement
 
 Design and implement a MinStack data structure that can store comparable elements and supports the stack operations `push(x)`, `pop()`, and `size()`,
 as well as the `min()` operation, which returns the minimum value currently stored in the data structure.
 
 All operations should run in constant time.
 
-2. Description of the Code:
-3. Errors and Warnings:
-4. Sample Input and Output:
-5. Discussion:
+## Description of the Code
+## Errors and Warnings
+## Sample Input and Output
+## Discussion