-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStack_using_single_linked_list.c
More file actions
79 lines (79 loc) · 1.74 KB
/
Copy pathStack_using_single_linked_list.c
File metadata and controls
79 lines (79 loc) · 1.74 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
#include<stdio.h>
#include<stdlib.h>
struct node{
int data;
struct node *next;
}*top,*p;
void push(){
p=(struct node*)malloc(sizeof(struct node));
printf("\nEnter data value: ");
scanf("%d",&p->data);
p->next=NULL;
if(top==NULL)
top=p;
else{
p->next=top;
top=p;
}
printf("\n%d is pushed.\n",top->data);
}
void pop(){
if(top==NULL)
printf("\nStact is empty!\n");
else{
p=top;
printf("\n%d is poped.\n",top->data);
top=top->next;
free(p);
}
}
void Display(){
p=top;
if(top==NULL)
printf("\nStack is empty.\n");
else{
printf("\nStack elements are: ");
while(p!=NULL){
printf("%d ",p->data);
p=p->next;
}
printf("\n");
}
}
void is_empty(){
if(top==NULL)
printf("\nStack is Empty!\n");
else
printf("\nStack is not empty.\n");
}
void peek(){
if(top==NULL)
printf("\nStack is Empty!\n");
else
printf("\nPeek element is : %d\n",top->data);
}
void main(){
int op;
while(1){
printf("\n* * * * * * * *\n");
printf("* 1. PUSH *\n* 2. POP *\n* 3. DISPLAY *\n* 4. IS EMPTY *\n* 5. PEEK *\n* 6. EXIT *\n");
printf("* * * * * * * *\n");
printf("\nEnter your option: ");
scanf("%d",&op);
switch(op){
case 1: push();
break;
case 2: pop();
break;
case 3: Display();
break;
case 4 : is_empty();
break;
case 5:peek();
break;
case 6:exit(0);
break;
default : printf("\nWRONG OPTION!\n");
}
}
}