-
Notifications
You must be signed in to change notification settings - Fork 12
/
P53StackHeaderTest.c
61 lines (57 loc) · 1.23 KB
/
P53StackHeaderTest.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Program P5.3
// For this program to work, the file stack.h (contents shown below)
// must be stored in the "include" folder of your compiler
#include <stdio.h>
#include <stack.h>
int main() {
int n;
Stack S = initStack();
printf("Enter some integers, ending with 0\n");
scanf("%d", &n);
while (n != 0) {
push(S, n);
scanf("%d", &n);
}
printf("\nNumbers in reverse order\n");
while (!empty(S))
printf("%d ", pop(S));
printf("\n");
}
// contents of stack.h, shown as comments. Uncomment to use.
//#include <stdlib.h>
//#define RogueValue -9999
//
//typedef struct node {
// int num;
// struct node *next;
//} Node, *NodePtr;
//
//typedef struct stackType {
// NodePtr top;
//} StackType, *Stack;
//
//Stack initStack() {
// Stack sp = (Stack) malloc(sizeof(StackType));
// sp -> top = NULL;
// return sp;
//}
//
//int empty(Stack S) {
// return (S -> top == NULL);
//} //end empty
//
//void push(Stack S, int n) {
// NodePtr np = (NodePtr) malloc(sizeof(Node));
// np -> num = n;
// np -> next = S -> top;
// S -> top = np;
//} //end push
//
//int pop(Stack S) {
// if (empty(S)) return RogueValue;
// int hold = S -> top -> num;
// NodePtr temp = S -> top;
// S -> top = S -> top -> next;
// free(temp);
// return hold;
//} //end pop