-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstackusinglinkedlist.c
More file actions
118 lines (100 loc) · 1.91 KB
/
stackusinglinkedlist.c
File metadata and controls
118 lines (100 loc) · 1.91 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
#include<stdio.h>
#include<stdlib.h>
struct node{
int data;
struct node* next;
};
int isempty(struct node* top){
if(top==NULL)
{
return 1;
}
else
{
return 0;
}
}
int isfull(){
struct node* p=(struct node*)malloc(sizeof(struct node));
if(p==NULL)
{
return 1;
}
else
{
return 0;
}
}
void traversel(struct node * ptr)
{
printf("\t\t\t**you list's element\n");
printf("\t\t\t*$$$$$$$$$*$\n");
while (ptr!=NULL)
{
printf("\t\t\t\tElement:%d\n",ptr->data);
ptr=ptr->next;
}
printf("\t\t\t*$$$$$$$$$*$\n");
}
struct node* push(struct node* top,int data)
{
if(isfull())
{
printf("stack overflow!!!");
return top;
}
else
{
struct node* n=(struct node*)malloc(sizeof(struct node));
n->data=data;
n->next=top;
top=n;
return top;
}
}
struct node* pop(struct node* top)
{
if(isempty(top))
{
printf("stack is empty\n");
}
else
{
struct node* temp = top;
top = top->next;
free(temp);
return top;
}
}
int main() {
int choice,n;
struct node* top = NULL;
while(1)
{
printf("press 1 :to push element.\n");
printf("press 2 :to pop element.\n");
printf("press 3 :show stack element.\n");
printf("press 4 :Exit\n");
printf("enter your choice:-");
scanf("%d",&choice);
switch (choice) {
case 1:
printf("Enter element to push: ");
scanf("%d", &n);
top = push(top, n);
break;
case 2:
top = pop(top);
break;
case 3:
traversel(top);
break;
case 4:
printf("Thank you... goodbye\n");
return 0;
default:
printf("Invalid choice\n");
}
}
return 0;
}