Created
October 10, 2017 17:38
-
-
Save tlively/3cfa46de5ace6338fe47d3336ddfefea to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdbool.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#define N_ITEMS 10 | |
/* Uncomment this section to use linked lists | |
typedef struct node | |
{ | |
int val; | |
struct node *next; | |
} | |
// the linked list | |
node *head; | |
*/ | |
/* Uncomment this section to use an array | |
#define ARRAY_LENGTH 20 | |
int array[ARRAY_LENGTH] = {}; | |
*/ | |
// pushes a value onto the stack. Returns true if successful, otherwise false. | |
bool push(int val) | |
{ | |
(void)val; | |
return false; | |
} | |
// pops a value off of the stack and returns it. | |
// The stack must have a value to pop. | |
int pop(void) | |
{ | |
return -1; | |
} | |
int main(void) | |
{ | |
// push numbers 1-10 onto the stack | |
for (int i = 0; i < N_ITEMS; i++) | |
{ | |
if (!push(i)) | |
{ | |
printf("Could not push %d\n", i); | |
return 1; | |
} | |
} | |
// pop the numbers off the stack and print them | |
for (int i = 0; i < N_ITEMS; i++) | |
{ | |
printf("%d\n", pop()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment