forked from junaidrahim/Hacktoberfest-KIIT-2021
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathImplementing a queue
70 lines (69 loc) · 1.07 KB
/
Implementing a queue
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
#include<stdio.h>
#include<stdlib.h>
struct node{
int data;
struct node *next;
};
void create(struct node **start);
void display(struct node **start);
int main()
{
int c=0,ch;
struct node *start=NULL,*newnode;
newnode=(struct node*)malloc(sizeof(struct node));
newnode->data=c;
newnode->next=NULL;
start=newnode;
while (1)
{
printf("1.Create\n");
printf("2.display\n");
printf("3.exit\n");
scanf("%d",&ch);
switch(ch)
{
case 1:
(start->data)++;
create(&start);
break;
case 2:
display(&start);
break;
case 3:
exit(1);
default:
printf("wrong choice\n");
}
}
return 0;
}
void create(struct node **start)
{
struct node *newnode,*temp=*start;
newnode=(struct node*)malloc(sizeof(struct node));
int data1;
printf("enter the data to be entered\n");
scanf("%d",&data1);
newnode->data=data1;
newnode->next=NULL;
temp=*start;
while (temp->next!=NULL)
{
temp=temp->next;
}
temp->next=newnode;
}
void display(struct node **start)
{
struct node *temp=*start;
printf("%d\n",temp->data);
struct node *ptr;
temp=*start;
ptr=temp->next;
while (ptr!=NULL)
{
printf("%d\t",ptr->data);
ptr=ptr->next;
}
printf("\n");
}