diff options
| author | mo khan <mo.khan@gmail.com> | 2020-07-05 13:26:57 -0600 |
|---|---|---|
| committer | mo khan <mo.khan@gmail.com> | 2020-07-05 13:26:57 -0600 |
| commit | c1eba569296eb591de1cae838e2d342f17ecb950 (patch) | |
| tree | 99dd9d2ced425762739c5ebe5e7b2e0c33800fa7 | |
| parent | 15db180b1df02c73dc8632e5ae1eb0f29e2dceaa (diff) | |
Add formatted output to program profile
| -rw-r--r-- | src/01/06/README.md | 138 | ||||
| -rw-r--r-- | src/01/06/main.c | 2 | ||||
| -rw-r--r-- | src/01/06/min_stack.c | 16 |
3 files changed, 145 insertions, 11 deletions
diff --git a/src/01/06/README.md b/src/01/06/README.md index c02bf45..c44a3df 100644 --- a/src/01/06/README.md +++ b/src/01/06/README.md @@ -12,5 +12,143 @@ All operations should run in constant time. ## Description of the Code ## Errors and Warnings + +```bash +モ make run_test +clang build/min_stack.o build/min_stack_test.o -lcgreen -o build/test +cgreen-runner -c -v build/test +Discovered MinStack:when_a_single_item_is_on_the_stack_it_has_a_size_of_one (CgreenSpec__MinStack__when_a_single_item_is_on_the_stack_it_has_a_size_of_one__) +Discovered MinStack:when_a_single_item_is_on_the_stack_it_is_the_min (CgreenSpec__MinStack__when_a_single_item_is_on_the_stack_it_is_the_min__) +Discovered MinStack:when_a_single_item_is_on_the_stack_when_it_is_popped_off_it_returns_a_min_of_null (CgreenSpec__MinStack__when_a_single_item_is_on_the_stack_when_it_is_popped_off_it_returns_a_min_of_null__) +Discovered MinStack:when_a_single_item_is_on_the_stack_when_it_is_popped_off_it_returns_a_size_of_zero (CgreenSpec__MinStack__when_a_single_item_is_on_the_stack_when_it_is_popped_off_it_returns_a_size_of_zero__) +Discovered MinStack:when_a_single_item_is_on_the_stack_when_it_is_popped_off_it_returns_the_item (CgreenSpec__MinStack__when_a_single_item_is_on_the_stack_when_it_is_popped_off_it_returns_the_item__) +Discovered MinStack:when_empty (CgreenSpec__MinStack__when_empty__) +Discovered MinStack:when_empty_it_has_a_min_of_null (CgreenSpec__MinStack__when_empty_it_has_a_min_of_null__) +Discovered MinStack:when_empty_it_has_a_size_of_zero (CgreenSpec__MinStack__when_empty_it_has_a_size_of_zero__) +Discovered MinStack:when_pushing_a_single_integer (CgreenSpec__MinStack__when_pushing_a_single_integer__) +Discovered MinStack:when_pushing_duplicate_values_on_to_the_stack (CgreenSpec__MinStack__when_pushing_duplicate_values_on_to_the_stack__) +Discovered MinStack:when_pushing_multiple_integers_out_of_order (CgreenSpec__MinStack__when_pushing_multiple_integers_out_of_order__) +Discovered 11 test(s) +Opening [build/test] to run all 11 discovered tests ... +Running "test" (11 tests)... + "MinStack": 39 passes in 7ms. +Completed "test": 39 passes in 7ms. +``` + ## Sample Input and Output + +```bash +モ make run +clang -c -o build/main.o main.c +clang build/min_stack.o build/main.o -o build/program +./build/program +=== COMP-272 - Assignment 1 - Question 6 === +Pushing: +========== +Push: 7, Min: 7 + [7] +Push: 24, Min: 7 + [24][7] +Push: 23, Min: 7 + [23][24][7] +Push: 8, Min: 7 + [8][23][24][7] +Push: 5, Min: 5 + [5][8][23][24][7] +Push: 22, Min: 5 + [22][5][8][23][24][7] +Push: 19, Min: 5 + [19][22][5][8][23][24][7] +Push: 3, Min: 3 + [3][19][22][5][8][23][24][7] +Push: 23, Min: 3 + [23][3][19][22][5][8][23][24][7] +Push: 9, Min: 3 + [9][23][3][19][22][5][8][23][24][7] +Push: 15, Min: 3 + [15][9][23][3][19][22][5][8][23][24][7] +Push: 15, Min: 3 + [15][15][9][23][3][19][22][5][8][23][24][7] +Push: 17, Min: 3 + [17][15][15][9][23][3][19][22][5][8][23][24][7] +Push: 17, Min: 3 + [17][17][15][15][9][23][3][19][22][5][8][23][24][7] +Push: 12, Min: 3 + [12][17][17][15][15][9][23][3][19][22][5][8][23][24][7] +Push: 3, Min: 3 + [3][12][17][17][15][15][9][23][3][19][22][5][8][23][24][7] +Push: 2, Min: 2 + [2][3][12][17][17][15][15][9][23][3][19][22][5][8][23][24][7] +Push: 4, Min: 2 + [4][2][3][12][17][17][15][15][9][23][3][19][22][5][8][23][24][7] +Push: 15, Min: 2 + [15][4][2][3][12][17][17][15][15][9][23][3][19][22][5][8][23][24][7] +Push: 12, Min: 2 + [12][15][4][2][3][12][17][17][15][15][9][23][3][19][22][5][8][23][24][7] +Push: 3, Min: 2 + [3][12][15][4][2][3][12][17][17][15][15][9][23][3][19][22][5][8][23][24][7] +Push: 19, Min: 2 + [19][3][12][15][4][2][3][12][17][17][15][15][9][23][3][19][22][5][8][23][24][7] +Push: 9, Min: 2 + [9][19][3][12][15][4][2][3][12][17][17][15][15][9][23][3][19][22][5][8][23][24][7] +Push: 7, Min: 2 + [7][9][19][3][12][15][4][2][3][12][17][17][15][15][9][23][3][19][22][5][8][23][24][7] +Push: 10, Min: 2 + [10][7][9][19][3][12][15][4][2][3][12][17][17][15][15][9][23][3][19][22][5][8][23][24][7] +Popping: +========== + [10][7][9][19][3][12][15][4][2][3][12][17][17][15][15][9][23][3][19][22][5][8][23][24][7] +Pop: 10, Min: 2 + [7][9][19][3][12][15][4][2][3][12][17][17][15][15][9][23][3][19][22][5][8][23][24][7] +Pop: 7, Min: 2 + [9][19][3][12][15][4][2][3][12][17][17][15][15][9][23][3][19][22][5][8][23][24][7] +Pop: 9, Min: 2 + [19][3][12][15][4][2][3][12][17][17][15][15][9][23][3][19][22][5][8][23][24][7] +Pop: 19, Min: 2 + [3][12][15][4][2][3][12][17][17][15][15][9][23][3][19][22][5][8][23][24][7] +Pop: 3, Min: 2 + [12][15][4][2][3][12][17][17][15][15][9][23][3][19][22][5][8][23][24][7] +Pop: 12, Min: 2 + [15][4][2][3][12][17][17][15][15][9][23][3][19][22][5][8][23][24][7] +Pop: 15, Min: 2 + [4][2][3][12][17][17][15][15][9][23][3][19][22][5][8][23][24][7] +Pop: 4, Min: 2 + [2][3][12][17][17][15][15][9][23][3][19][22][5][8][23][24][7] +Pop: 2, Min: 3 + [3][12][17][17][15][15][9][23][3][19][22][5][8][23][24][7] +Pop: 3, Min: 5 + [12][17][17][15][15][9][23][3][19][22][5][8][23][24][7] +Pop: 12, Min: 5 + [17][17][15][15][9][23][3][19][22][5][8][23][24][7] +Pop: 17, Min: 5 + [17][15][15][9][23][3][19][22][5][8][23][24][7] +Pop: 17, Min: 5 + [15][15][9][23][3][19][22][5][8][23][24][7] +Pop: 15, Min: 5 + [15][9][23][3][19][22][5][8][23][24][7] +Pop: 15, Min: 5 + [9][23][3][19][22][5][8][23][24][7] +Pop: 9, Min: 5 + [23][3][19][22][5][8][23][24][7] +Pop: 23, Min: 5 + [3][19][22][5][8][23][24][7] +Pop: 3, Min: 5 + [19][22][5][8][23][24][7] +Pop: 19, Min: 5 + [22][5][8][23][24][7] +Pop: 22, Min: 5 + [5][8][23][24][7] +Pop: 5, Min: 7 + [8][23][24][7] +Pop: 8, Min: 7 + [23][24][7] +Pop: 23, Min: 7 + [24][7] +Pop: 24, Min: 7 + [7] +Pop: 7, Min: 0 + +Bye +``` + ## Discussion diff --git a/src/01/06/main.c b/src/01/06/main.c index e5ab439..6a86346 100644 --- a/src/01/06/main.c +++ b/src/01/06/main.c @@ -23,7 +23,7 @@ int main(int argc, char *argv[]) inspect(stack); } - printf("Bye"); + printf("Bye\n"); free(stack); return 0; } diff --git a/src/01/06/min_stack.c b/src/01/06/min_stack.c index 7567cd6..867dce8 100644 --- a/src/01/06/min_stack.c +++ b/src/01/06/min_stack.c @@ -22,14 +22,12 @@ int size(Stack *self) { } void push(Stack *self, int data) { - if (self->min) { - if (data < self->min->data) { - Node *tmp = new(data); - tmp->next = self->min; - self->min = tmp; - } - } else { + if (!self->min) self->min = new(data); + else if (data < self->min->data) { + Node *tmp = new(data); + tmp->next = self->min; + self->min = tmp; } Node *node = new(data); @@ -72,10 +70,8 @@ int pop(Stack *self) { Node *current = self->head; int data = current->data; - if (data == self->min->data) { + if (data == self->min->data) self->min = self->min->next; - } - self->head = current->next; self->size--; current->next = NULL; |
