c++ q

☆C언어/소스 2018. 9. 19. 01:56

//기본적인 큐라 효율이 쓰래기

#include<iostream>

using namespace::std;


template<typename T>

class Queue

{

enum { cap = 10 };

T arr[cap];

int front;

int rear;


public:


Queue() :front(0), rear(0) {};


void Push(T num)

{

arr[rear = (rear + 1) % cap] = num;

}

void Pop()

{

cout << arr[front=(front+1)%cap] << endl;

}

bool Empty()

{

return front == rear;

}

};


int main()

{


Queue<int> q;



q.Push(10);

q.Pop();

q.Empty();

q.Push(20);

q.Push(30);


q.Pop();

q.Pop();

q.Pop();



}

'☆C언어 > 소스' 카테고리의 다른 글

8-3 연습문제  (0) 2018.09.18
문자열 숫자 쉽게 숫자로 바꾸기  (0) 2017.12.25
'q' 입력시 종료  (0) 2017.11.21
달력  (0) 2017.11.13
괄호 검사  (0) 2017.06.17