-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstack.c
48 lines (40 loc) · 830 Bytes
/
stack.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
#include <stdio.h>
#include "stack.h"
#include <stdlib.h>
char pop(StackNodePtr *topPtr)
{
StackNodePtr top = *topPtr;
char data = top->data;
*topPtr = (*topPtr)->nextPtr;
free(top);
return data;
}
char stackTop(StackNodePtr topPtr)
{
if (isEmpty(topPtr) == 0 ){
return topPtr->data;
} else {
return '\0';
}
}
void push(StackNodePtr *topPtr, char value)
{
StackNodePtr toPush = malloc(sizeof(StackNodePtr));
if (toPush != NULL) {
toPush->data = value;
toPush->nextPtr = *topPtr;
*topPtr =toPush;
}
}
int isEmpty(StackNodePtr topPtr)
{
return (topPtr == NULL);
}
void printStack(StackNodePtr topPtr)
{
while(topPtr != NULL) {
printf("%c\n", topPtr->data);
topPtr=topPtr->nextPtr;
}
printf("NULL \n");
}