본문 바로가기

둥지49

[백준 1992] 쿼드 트리 문제링크 #include #include char arr[100][100] = {}; void f(int a, int b, int n) { int flag = 0; int j = 0; for (int i = 0; i arr[i]; } f(0, 0, n); return 0; } 2023. 2. 20.
리스트 구현 #include template class LinkedList { class Node { friend LinkedList; public: Node() {}; Node(T& _data) : data(_data), next(nullptr), prev(nullptr) { } T data; Node* next; Node* prev; }; public: LinkedList() : head(new Node()) , tail(new Node()) { head->next = tail; tail->prev = head; } ~LinkedList() { Node* node = head; while (nullptr != node) { Node* next = node->next; delete node; node = nullp.. 2023. 2. 17.
큐 구현 #include #include enum { MAX_SIZE = 3 }; template class MyQueue { T Array_[MAX_SIZE]; size_t Count_ = 0; size_t Front_ = 0; size_t Rear_ = 0; public: void Enqueue(T Data) { if (true == IsFull()) { assert(false); } Array_[Rear_] = Data; Rear_ = (Rear_ + 1) % MAX_SIZE; //원형 큐 ++Count_; } bool IsFull() { return Front_ == (Rear_ + 1) % MAX_SIZE; } bool IsEmpty() { return Front_ == Rear_; } T Dequeue.. 2023. 2. 10.
스택 구현 #include #include constexpr int MAX_COUNT = 100001; template class MyEnum { T Array_[MAX_COUNT]; size_t Size_; public: void Push(T Data) { Array_[Size_] = Data; ++Size_; } bool IsEmpty() { if (0 < Size_) { return false; } return true; } T Pop() { if (true == IsEmpty()) { assert(false); } return Array_[--Size_]; } }; int main() { MyEnum myEnum = {}; myEnum.Push(3); myEnum.Push(3); myEnum.Push(3);.. 2023. 2. 9.
가변 배열 구현 #include template class MyVector { T* Array_; size_t Size_; size_t Capacity_; public: MyVector() { Array_ = new T[2 * sizeof(T)]; Capacity_ = 2 * sizeof(T); Size_ = 0; } ~MyVector() { } size_t Size() const { return Size_; } void Release() { delete Array_; Array_ = nullptr; } void Resize() { T* TempArray_; TempArray_ = new T[Capacity_ * 2 * sizeof(T)]; for (size_t i = 0; i < Size_; ++i) { TempArr.. 2023. 2. 9.
배열 구현 #include constexpr int INVALID_INDEX = -1; constexpr int MAX_COUNT = 101; template class MyArray { T Array_[MAX_COUNT]; size_t Size_; public: void Insert(size_t _Index, T _Data) { if (0 == _Index) { Array_[_Index] = _Data; ++Size_; return; } for (size_t i = Size_; i > _Index; --i) { Array_[i] = Array_[i - 1]; } Array_[_Index] = _Data; ++Size_; } void OrderlyRemove(size_t _Index) { for (size_t i .. 2023. 2. 8.