-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstacklink.c
68 lines (67 loc) · 1 KB
/
stacklink.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
#include<stdio.h>
#include<stdlib.h>
// testing
struct node {
int data;
struct node *link;
} *head=NULL;
void insertf();
void deletef();
void display();
void main()
{
int x;
loop:
printf("\n\nSelect an operation :\n1. insert\n2. delete(front)\n3. display\n");
scanf("%d",&x);
switch (x)
{
case 1: insertf();
goto loop;
case 2: deletef();
goto loop;
case 3: display();
goto loop;
default : printf("Wrong selection, try again\n");
goto loop;
}
}
void insertf()
{
struct node *newNode;
newNode = malloc(sizeof(struct node));
printf("Enter the element to be inserted\n");
scanf("%d",&newNode->data);
newNode->link = head;
head = newNode;
}
void deletef()
{
struct node *temp;
if(head == NULL)
{
printf("list is empty\n");
}
else
{
printf("Element %d has been deleted\n",head->data);
head = head->link;
}
}
void display()
{
struct node *temp = head;
if(head == NULL)
{
printf("list is empty\n");
}
else
{
printf("\n\nList elements are : \n");
while(temp != NULL)
{
printf("%d ",temp->data);
temp = temp->link;
}
}
}