본문 바로가기
Computer Science

queue

by OKOK 2019. 1. 17.

1. 오케이 어떻게 사용하는지 접수

2. 사용 방법 받아들임 


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
88
89
90
91
92
93
94
95
96
97
98
#include <stdio.h>
 
#define MAX_N 100
 
int front;
int rear;
int queue[MAX_N];
 
void queueInit(void)
{
    front = 0;
    rear = 0;
}
 
int queueIsEmpty(void)
{
    return (front == rear);
}
 
int queueIsFull(void)
{
    if ((front + 1) % MAX_N == rear)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}
 
int queueEnqueue(int value)
{
    if (queueIsFull())
    {
        printf("queue is full!");
        return 0;
    }
    queue[front= value;
    front++;
    if (front == MAX_N)
    {
        front = 0;
    }
 
    return 1;
}
 
int queueDequeue(int *value)
{
    if (queueIsEmpty())
    {
        printf("queue is empty!");
        return 0;
    }
    *value = queue[rear];
    rear++;
    if (rear == MAX_N)
    {
        rear = 0;
    }
    return 1;
}
 
int main(int argc, char* argv[])
{
    freopen("input.txt""r", stdin);
    int T;
    int N;
 
    scanf("%d"&T);
 
    for (int test_case = 1; test_case <= T; test_case++)
    {
        scanf("%d"&N);
 
        queueInit();
        for (int i = 0; i < N; i++)
        {
            int value;
            scanf("%d"&value);
            queueEnqueue(value);
        }
 
        printf("#%d ", test_case);
 
        while (!queueIsEmpty())
        {
            int value;
            if (queueDequeue(&value) == 1)
            {
                printf("%d ", value);
            }
        }
        printf("\n");
    }
    return 0;
}
cs

 


'Computer Science' 카테고리의 다른 글

동적할당 대신 사용할 수 있는 배열  (0) 2019.01.17
2019112 우선순위 큐, 힙, 링크드 리스트  (0) 2019.01.17
stack  (0) 2019.01.17
Tree PreOrder  (0) 2019.01.16
Graph  (0) 2019.01.16

댓글