-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnisarg.c
87 lines (75 loc) · 1.14 KB
/
nisarg.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include<stdio.h>
//#include<queue.h> this is bydefault existed
#define MaxQ 10
typedef struct
{
int head,tail;
int QA[MaxQ];
}QType,*Queue;
Queue initQueue();
int empty(Queue Q);
void enqueue(Queue Q,int n);
int dequeue(Queue Q);
Queue initQueue()
{
Queue qp = (Queue)malloc(sizeof(QType));
qp->head=qp->tail=0;
return qp;
}
int empty(Queue Q)
{
return(Q->head==Q->tail);
}
void enqueue(Queue Q,int n)
{
if(Q->tail==MaxQ-1)
{
Q->tail=0;
}
else
{
++(Q->tail);
}
if(Q->tail==Q->head)
{
printf("\nQueue is full");
exit(1);
}
Q->QA[Q->tail]=n;
}
int dequeue(Queue Q)
{
if(empty(Q))
{
printf("\nAttempt to remove from an empty queue........\n");
exit(1);
}
if(Q->head==MaxQ-1)
{
Q->head=0;
}
else
{
++(Q->head);
}
return Q->QA[Q->head];
}
main()
{
int n;
Queue Q = initQueue();
printf("Enter the positive integer : ");
scanf("%d",&n);
while(n>0)
{
enqueue(Q,n%10);
n=n/10;
}
printf("\nDigit in reverse");
while(!empty(Q))
{
printf("%d",dequeue(Q));
}
printf("\n\n");
system("pause");
}