-
Notifications
You must be signed in to change notification settings - Fork 6
/
QLin.c
executable file
·65 lines (64 loc) · 1.02 KB
/
QLin.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
#include<stdio.h>
#include<malloc.h>
struct node
{
int data;
struct node *next;
}*front = NULL, *rear = NULL;
void push (int item)
{
struct node *p;
p=(struct node *)malloc(sizeof(struct node));
p->next=NULL;
p->data=item;
if(rear == NULL)
{
rear = p;
front = p;
}
else
{
rear->next=p;
rear=p;
}
}
void display ()
{
struct node *p;
//p=(struct node *)malloc(sizeof(struct node));
p=front;
while(p!=NULL)
{
printf("%d\n",p->data);
p=p->next;
//counter++;
}
}
void pop ()
{
if(rear==front)
{
printf("Cannot Delete\n");
}
else
{
struct node *p;
p=front;
printf("The element which is being deleted is as follows : %d\n",front->data);
front=front->next;
free(p);
}
}
int main ()
{
int num = 0;
while(num!=4)
{
printf("Enter your choice : ");
scanf("%d",&num);
if(num == 1){int item;printf("Enter the element you want to push : ");scanf("%d",&item);push(item);}
if(num == 2){pop();}
if(num == 3){display ();}
}
return 0;
}