- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstacklinked.c
More file actions
Latest commit
124 lines (104 loc) · 1.82 KB
/
Copy pathstacklinked.c
File metadata and controls
124 lines (104 loc) · 1.82 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#include<stdio.h>
#include<stdlib.h>
intmax=5;
structNode
{
intdata;
structNode*link;
};
intcount=0;
structNode*top=NULL;
/*void push(int val)
{
if (count==max)
{
printf("Stack is full");
}
else
{
struct Node *newNode = malloc(sizeof(struct Node));
newNode->data = val;
newNode->link = top;
top = newNode;
count++;
}
}
void pop()
{
struct Node *temp;
if(top == NULL)
printf("Stack is Empty\n");
else
{
printf("Poped element = %d\n", top->data);
temp = top;
top = top->link;
count--;
}
}
void display()
{
struct Node *temp = top;
while(temp != NULL)
{
printf("%d\t", temp->data);
temp = temp->link;
}
}*/
voidpush(intvalue)
{
ptr=head;
if(count==max)
{
printf("Stack Full");
}
else
{
temp=(structnode*)malloc(sizeof(structnode));
temp->data=value;
temp->link=NULL;
top=temp;
}
}
voidpop()
{
ptr=head;
if(top==NULL)
{
printf("Underflow");
}
else
{
while(ptr->link->link!=NULL)
{
ptr=ptr->link;
}
ptr->link=NULL;
free(ptr);
}
}
intmain()
{
intop,val;
printf("Enter value of max:");
scanf("%d",&max);
printf("1.PUSH \n2.POP \n3.DISPLAY \n4.EXIT");
while(1)
{
printf("\nEnter choice:");
scanf("%d",&op);
switch(op)
{
case1:printf("Enter value:");
scanf("%d",&val);
push(val);
break;
case2:pop();
break;
case3:
display();
break;
case4:exit(0);
}
}
}