큐5 [백준/BOJ][C++] 11866번 요세푸스 문제0 #include #include using namespace std; int main() { // 쓰레드 환경이 아닐때 버퍼를 분리하여 처리속도를 빠르게 해줌 ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int N, K; cin >> N >> K; queue circle; // 순서대로 사람을 앉힘 for (int i = 1; i 2023. 8. 24. [백준/BOJ][C++] 2164번 카드2 #include #include using namespace std; void Shuffle(queue& q) { q.pop(); // 맨 위의 카드를 버림 q.push(q.front()); // 그 다음 맨 위의 카드를 밑으로 옮김 q.pop(); // 옮긴 카드를 버림 } int main() { // 쓰레드 환경이 아닐때 버퍼를 분리하여 처리속도를 빠르게 해줌 ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int N; cin >> N; queue q; // 1부터 N까지 수를 큐에 담음 for (int i = 1; i 2023. 8. 24. [백준/BOJ][C++] 18258번 큐 2 #include #include using namespace std; struct Queue { private: int* elements; int frontIndex; int backIndex; public: Queue(int n) { elements = new int[n]; frontIndex = 0; backIndex = -1; } ~Queue() {} void push(int x) { elements[++backIndex] = x; } int pop() { if (empty()) return -1; else { return elements[frontIndex++]; } } int size() { return backIndex - frontIndex + 1; } bool empty() { if (fr.. 2023. 8. 24. [백준/BOJ][C++] 12789번 도키도키 간식드리미 #include #include #include using namespace std; int main() { // 쓰레드 환경이 아닐때 버퍼를 분리하여 처리속도를 빠르게 해줌 ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int N; cin >> N; queue curLine; // 현재 줄 stack otherLine; // 또 다른 줄 for (int i = 0; i > x; curLine.push(x); } int checkNum = 1; while (true) { if (!curLine.empty() && curLine.front() == checkNum) { // 현재 줄에 순서에 맞.. 2023. 8. 23. [면접 준비][자료구조] 스택과 큐의 차이점 1. 스택(Stack) - 나중에 들어간 것이 먼저 나오는 후입선출의 구조이다.(LIFO) - 비어있는 스택에서 원소를 추출하면 stack underflow - 스택이 넘치는 경우 stack overflow - ex) 뒤로가기, 실행취소, 역순 문자열 만들기 등 2. 큐(Queue) - 먼저 들어간 것이 먼저 나오는 선입선출의 구조(FIFO) - 한쪽 끝에서는 삽입 작업이, 다른 쪽 끝에서는 삭제 작업이 양쪽으로 이루어짐 - ex) 줄을 서서 기다려야하는 모든 행동들, 프로세스 관리, 너비우선탐색(BFS) 등 스택은 나중에 들어간 것이 먼저 나오는 후입선출, LIFO의 구조이고, 큐는 먼저 들어간 것이 먼저 나오는 선입선출, FIFO의 구조입니다. 스택의 예시로는 실행취소 등이 있고, 큐의 예시로는 줄을.. 2023. 7. 22. 이전 1 다음