-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueueeg.c
More file actions
68 lines (66 loc) · 1.68 KB
/
Copy pathQueueeg.c
File metadata and controls
68 lines (66 loc) · 1.68 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
/*-------------------------------------------------------------------------------------------------------------------------------
Queueeg.c
Program to create a queue using linked list
DIVYA RAJ K5
11-11-2018
---------------------------------------------------------------------------------------------------------------------------------*/
#include<stdio.h>
#include<stdlib.h>
typedef struct QueType{
int Num;
struct QueType *Next;
}QUENODE;
//-------------------------prototype--------------------------------------------
QUENODE *fnCreateQueueNode(int Num);
void fnInsertQueNode(QUENODE **Head,int Num);
void displayQueue(QUENODE *Head);
main()
{
QUENODE *p,*Head;
int Num,N,i;
system("clear");
Head=NULL;
printf("Program to create a queue using the concept of linked list\n\n");
printf("\nEnter the number of nodes you have to insert: ");
scanf("%d",&N);
printf("\nEnter the elements: \n");
for(i=1;i<=N;i++){
scanf("%d",&Num);
fnInsertQueNode(&Head,Num);
}
printf("\nThe elements in the queue are:\n");
displayQueue(Head);
}
//----------------------fnCreateQueueNode()---------------------------------------
QUENODE *fnCreateQueueNode(int Num)
{
QUENODE *Node;
Node=(QUENODE *)malloc(sizeof(QUENODE));
Node->Num=Num;
Node->Next=NULL;
return Node;
}
//----------------------fnInsertQueNode------------------------------------------
void fnInsertQueNode(QUENODE **Head,int Num)
{
QUENODE *p,*Curr;
p=fnCreateQueueNode(Num);
Curr=*Head;
if(Curr==NULL){
*Head=p;
return;
}
while((Curr!=NULL) && (Curr->Next)!=NULL){
Curr=Curr->Next;
}
Curr->Next=p;
}
void displayQueue(QUENODE *Head)
{
QUENODE *Curr;
Curr=Head;
while(Curr!=NULL){
printf("%d\t",Curr->Num);
Curr=Curr->Next;
}
}