-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Expand file tree
/
Copy pathstack_ll.c
More file actions
86 lines (85 loc) · 1.36 KB
/
stack_ll.c
File metadata and controls
86 lines (85 loc) · 1.36 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
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
struct node
{
int data;
struct node *next;
}*top=NULL,*new,*temp;
void push();
void pop();
void peek();
void display();
void main()
{
int c=0;
while(c!=5)
{
printf("\nEnter \n1:Push\n2:Pop\n3:Peek\n4:Display\n5:Exit");
scanf("%d",&c);
switch (c)
{
case 1:
push();
break;
case 2:
pop();
break;
case 3:
peek();
break;
case 4:
display();
break;
case 5:
exit;
break;
}
}
free(new);
free(top);
free(temp);
}
void push()
{
new=(struct node *)malloc(sizeof(struct node));
printf("Enter the value");
scanf("%d",&new->data);
if(top==NULL)
{
new->next=NULL;
top=new;
}
else
{
new->next=top;
top=new;
}
printf("\nNode inserted");
}
void pop()
{
if(top==NULL)
{
printf("Stack is empty");
}
else
{
temp=top;
top=top->next;
free(temp);
}
}
void peek()
{
printf("top - %d",top->data);
}
void display()
{
temp=top;
while(temp!=NULL)
{
printf("%d - ",temp->data);
temp=temp->next;
}
}