본문 바로가기

둥지/알고리즘20

버블 정렬 #include #include template class DataManager { public: DataManager() {}; DataManager(size_t _Size) { Datas.resize(_Size); }; ~DataManager() {}; void Swap(T& _Left, T& _Right) { T Temp(_Left); _Left = _Right; _Right = Temp; } bool Compare(const T& _Left, const T& _Right) { return _Left < _Right; } void BubbleSort() { size_t Size = Datas.size(); for (size_t i = 0; i < Size - 1; ++i) { for (size_t .. 2023. 2. 25.
Array, Vector 구현 #include #include #include using namespace std; template class Array { T* Array_; size_t Size_; public: Array() : Array_(nullptr) , Size_(S) { Array_ = new T[Size_]; } ~Array() { delete[] Array_; Array_ = nullptr; } size_t Capacity() { return Size_; } void Resize(size_t _Size) { T* Temp = Array_; Array_ = new T[_Size]; for (size_t i = 0; i < _Size; i++) { Array_[i] = Temp[i]; } if (nullptr != Te.. 2023. 2. 20.
[백준 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.