-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueue.c
More file actions
60 lines (58 loc) · 1.12 KB
/
Queue.c
File metadata and controls
60 lines (58 loc) · 1.12 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
#include<stdio.h>
#include<stdlib.h>
typedef struct Node{
int data;
struct Node *next;
}node;
node *top=NULL;
void traversal(){
node *current=top;
while(current!=NULL){
printf("%d\t",current->data);
current=current->next;
}
printf("\n");
}
void enqueue(int data){
node *newnode=(node*)malloc(sizeof(node));
newnode->next=NULL;
newnode->data=data;
if(top==NULL){
top=newnode;
}else{
node *current=top;
while(current->next!=NULL){
current=current->next;
}
current->next=newnode;
}
}
void dequeue(){
node *deleteNode;
if(top==NULL){
printf("Queue is Empty\n");
return ;
}else{
deleteNode=top;
top=top->next;
free(deleteNode);
}
}
int main(){
int n,x;
printf("How many data you insert ? ");
scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%d",&x);
enqueue(x);
}
traversal();
int y;
printf("How many data you delete ? :");
scanf("%d",&y);
for(int i=1;i<=y;i++){
dequeue();
}
traversal();
return 0;
}