-
Notifications
You must be signed in to change notification settings - Fork 2
/
ADT_Linklist_as_stack.c
77 lines (69 loc) · 1.75 KB
/
ADT_Linklist_as_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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// author: jaydattpatel
#include <stdio.h>
#include <stdlib.h>
// Creating a node
struct node
{
int value;
struct node *next;
};
typedef struct node NODE;
NODE *start = NULL;
void push()
{
int a;
printf("\nEnter Value:"); scanf("%d",&a);
NODE *newnode;
newnode = (NODE*)malloc(sizeof(NODE));
newnode->value = a;
newnode->next = start;
start = newnode;
};
void pop()
{
NODE *top = start;
if(start == NULL)
{
printf("\nStack is Empty !! Deletion not possible");return;
}
else{start = top->next; free(top);}
};
void display()
{
NODE *top = start;
if(start == NULL)
{printf("\nStack is Empty !!");}
else
{
while(top != NULL)
{printf("%d",top->value); printf("->"); top = top->next;}
printf("NULL");
}
};
int main()
{
int value,choice;
while(1)
{
printf("\n***********Menu*************Stack Implimentation Usink Linked List\n");
printf("1.Push\t2.Pop\t3.Display\t4.Exit");
printf("\nEnter your choice:");
scanf("%d",&choice);
switch(choice)
{
case 1:{push(); display(); break;}
case 2:
{
if(start != NULL)
{
printf("The deleted elements:%d\n",start->value);
};
pop(); display(); break;
}
case 3:{display(); break;}
case 4:{exit(0);}
default:{printf("\nFunction Terminated."); exit(0);}
}
}
return(0);
}