-
Notifications
You must be signed in to change notification settings - Fork 0
/
week8-2.c
53 lines (43 loc) · 1.01 KB
/
week8-2.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
#include <stdio.h>
#include <stdlib.h>
struct Queue{
int capacity;
int front;
int rear;
int size;
int * array;
}
struct Queue * createQueue(int capacity){
struct Queue * queue=(struct Queue *)malloc(sizeof(struct Queue));
queue->capacity=capacity;
queue->size=0;
queue->front=-1;
queue->rear=capacity-1;
queue->array=(int *)malloc(sizeof(int)*capacity);
return queue;
}
int isFull(struct Queue * queue){
return (queue->size==queue->capacity);
}
int isEmpty(struct Queue * queue){
return(queue->size==0);
}
void enqueue(struct Queue * queue){
if (isFull(queue))
return;
queue->rear = (queue->rear + 1)%queue->capacity;
queue->array[queue->rear] = item;
queue->size = queue->size + 1;
}
void dequeue(struct Queue * queue){
if (isEmpty(queue))
return INT_MIN;
int item = queue->array[queue->front];
queue->front = (queue->front + 1)%queue->capacity;
queue->size = queue->size - 1;
return item;
}
void push(struct Queue * queue1,struct Queue * queue2){
}
int main(){
}