죠노이 노트

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
#include<iostream>
#include<string>
 
typedef struct Node {
    std::string data;
}Node;
 
class cir_queue {
private:
    Node* node;
    int size;
    int front;
    int back;
public:
    cir_queue(int size) {
        this->size = size + 1//더미 공간
        node = new Node[this->size];
        front = 0; back = 0;
    }
    
    void enqueue(std::string data) {
        int index;
 
        if (back == size - 1){
            index = back;
            back = 0;
        }
        else {
            index = back++;
        }
 
        node[index].data = data;
    }
    
    std::string dequeue() {
        int index = front;
 
        if (front == size - 1front = 0;
        else front++;
 
        return node[index].data;
    }
 
    int get_size() {
        if (front <= back) return back - front;
        else return size - front + back;
    }
};
 
 
cs


'개발 > 자료구조' 카테고리의 다른 글

[자료구조] c++ 스택  (0) 2016.11.17
q_sort  (1) 2016.11.16
[자료구조] Select Sort  (0) 2016.10.26
Recursive 를 이용한 Permutation Generator (순열 생성기)  (0) 2016.10.25
Binary Search 이진 탐색  (0) 2016.10.25