/* 2. ´ÙÀ½ ÇÁ·Î±×·¥ÀÇ Ãâ·ÂÀ» ½á¶ó. */ #include class Queue { static class Node { public: int data; Node *next; Node(int d, Node *n) { data = d; next = n; } }; Node *head; Node *tail; public: Queue() { head = new Node(0,NULL); tail = head; head->next = tail; } void add(int x) { tail = new Node(x,head); } void remove() { head = head->next; } void print(int n) { for (int i = 0; i < n; i++) { printf("%d\n",tail->data); tail = tail->next; } } }; void main() { int data[5] = { 1, 2, 3, 4, 5 }; // ¿©±â¸¦ ¹Ù²Ü °Í Queue x; for(int i = 0; i < 5; i++) { x.add(data[i]); x.remove(); } x.print(5); }