-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack.c
More file actions
51 lines (51 loc) · 873 Bytes
/
Copy pathstack.c
File metadata and controls
51 lines (51 loc) · 873 Bytes
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
#include<stdio.h>
#include<stdlib.h>
void PUSH(int val);
void PRINT();
void POP();
struct stackNode{
int value;
struct stackNode *next;
};
struct stackNode *Top = NULL;
int main(){
PUSH(5);
PUSH(10);
PUSH(15);
PUSH(20);
PUSH(25);
PRINT();
POP();
POP();
PRINT();
}
void PUSH(int val){
struct stackNode *ptr;
ptr = (struct stackNode*) malloc (sizeof(struct stackNode));
ptr->next = Top;
ptr->value = val;
Top = ptr;
}
void POP(){
if(Top == NULL){
printf("***Stack is Empty***\n");
}else{
struct stackNode *curr = Top;
printf("Deleted: %d\n",curr->value);
Top = Top->next;
free(curr);
}
}
void PRINT(){
printf("The Elements of Stack are: \n");
if(Top == NULL){
printf("***Stack is Empty***");
}else{
struct stackNode *curr = Top;
while(curr != NULL){
printf("%d -> ",curr->value);
curr = curr->next;
}
printf("NULL\n\n");
}
}