Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 구현
- 코테
- 그래프
- DP
- 정석학술정보관
- 개발
- 알고리즘
- coding
- 북리뷰
- 오퍼레이팅시스템
- c++
- cs
- 컴공과
- 백준
- Stack
- 오에스
- 문제풀이
- Computer science
- 컴퓨터공학과
- 너비우선탐색
- Operating System
- 자료구조
- 정석
- 브루트포스
- 스택
- bfs
- OS
- 컴공
- 코딩
- vector
Archives
- Today
- Total
Little Jay
[C++] 자료구조/Queue 구현 본문
#include <iostream>
#include <string>
using namespace std;
class Node {
public:
int data;
Node* next;
Node(int data) {
this->data = data;
this->next = NULL;
}
};
class LinkedList {
public:
Node* f;
Node* r;
LinkedList() {
f = NULL;
r = NULL;
}
~LinkedList() {
}
int front() {
return f->data;
}
int end() {
return r->data;
}
void addBack(int data) {
Node* n = new Node(data);
if (f == NULL) {
f = r = n;
}
else {
r->next = n;
r = n;
}
}
void removeFront() {
Node* old = f;
int show = old->data;
cout << show << "\n";
f = old->next;
delete old;
if (f == NULL) {
r = NULL;
}
}
};
class LinkedQueue {
public:
LinkedList* s;
int n;
int max_size;
LinkedQueue(int size) {
this->s = new LinkedList();
this->n = 0;
this->max_size = size;
}
int size() {
return n;
}
bool isEmpty() {
return (n == 0);
}
void front() {
if (isEmpty()) {
cout << "Empty" << '\n';
}
else {
cout << s->front() << "\n";
}
}
void rear() {
if (isEmpty()) {
cout << "Empty" << '\n';
}
else {
cout << s->end() << "\n";
}
}
void enqueue(int x) {
if (size() == max_size) {
cout << "Full" << "\n";
}
else {
s->addBack(x);
n++;
}
}
void dequeue() {
if (isEmpty()) {
cout << "Empty" << "\n";
}
else {
s->removeFront();
n--;
}
}
};
'알고리즘 > DataStructure' 카테고리의 다른 글
Quick Sort, MergeSort with 백준 2751번 (0) | 2022.03.28 |
---|---|
[C++] 자료구조/Stack 구현 (0) | 2021.11.20 |
Linked List Simple Question (0) | 2021.09.25 |
[C++] 자료구조/LinkedList 구현 (0) | 2021.08.28 |
[C++] 자료구조/Array 구현 (0) | 2021.07.22 |
Comments