-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcrack_4_2.c
More file actions
62 lines (54 loc) · 887 Bytes
/
crack_4_2.c
File metadata and controls
62 lines (54 loc) · 887 Bytes
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
#include <stdio.h>
#include <stdlib.h>
#define MAXSIZE 100
typedef struct Queue {
int head;
int tail;
int array[MAXSIZE];
} Queue;
Queue *initQueue();
void push(int);
int pop();
int front();
int empty();
Queue *qu;
main()
{
qu = initQueue();
push(1);
push(2);
push(3);
printf("%d\n", pop());
printf("%d\n", front());
return 0;
}
Queue *initQueue()
{
Queue *q = (Queue *)malloc(sizeof(Queue));
q->head = 0;
q->tail = 0;
return q;
}
void push(int data)
{
if (qu->head <= qu->tail && qu->tail < MAXSIZE)
(qu->array)[(qu->tail)++] = data;
}
int pop()
{
if (qu->head <= qu->tail && qu->tail < MAXSIZE)
return (qu->array)[(qu->head)++];
qu->head = 0;
qu->tail = -1;
return -1;
}
int front()
{
if (qu->head <= qu->tail && qu->tail < MAXSIZE)
return (qu->array)[qu->head];
return -1;
}
int empty()
{
return (qu->head >= qu->tail && qu->head != 0) ? 1 : 0;
}