diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..70e34ec --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "C_Cpp.errorSquiggles": "disabled" +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..6532339 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,28 @@ +{ + "tasks": [ + { + "type": "cppbuild", + "label": "C/C++: cl.exe build active file", + "command": "cl.exe", + "args": [ + "/Zi", + "/EHsc", + "/nologo", + "/Fe${fileDirname}\\${fileBasenameNoExtension}.exe", + "${file}" + ], + "options": { + "cwd": "${fileDirname}" + }, + "problemMatcher": [ + "$msCompile" + ], + "group": { + "kind": "build", + "isDefault": true + }, + "detail": "Task generated by Debugger." + } + ], + "version": "2.0.0" +} \ No newline at end of file diff --git a/README.md b/README.md index 0ce1494..d59a205 100644 --- a/README.md +++ b/README.md @@ -12,8 +12,4 @@ * 2주차 과제 * 3주차 과제 * 4주차 과제 -* 5주차 과제 - -과제1 -이 수업에서 배우고 싶은 것 : 대략적인 자료구조 내용 -얻어가고 싶은 것 : 자료구조를 배우다 어려운 파트나 모르는 파트 해결하고 가기 \ No newline at end of file +* 5주차 과제 \ No newline at end of file diff --git a/w1/README.md b/w1/README.md index 92e5ce4..b8b08e1 100644 --- a/w1/README.md +++ b/w1/README.md @@ -1 +1,5 @@ 여기에 1주차 과제를 작성해주시면 됩니다! + +과제1 +이 수업에서 배우고 싶은 것 : 대략적인 자료구조 내용 +얻어가고 싶은 것 : 자료구조를 배우다 어려운 파트나 모르는 파트 해결하고 가기 \ No newline at end of file diff --git a/w1/test.cpp b/w1/test.cpp index 770947a..ca831d8 100644 --- a/w1/test.cpp +++ b/w1/test.cpp @@ -1,7 +1,127 @@ #include +#include using namespace std; -int main() -{ - cout << "hello world"; -} \ No newline at end of file +// int main() +// { +// cout << "hello world"; +// } + +// class ArrayStack { +// private: +// int *arr; +// int top; +// int capacity; +// public: +// ArrayStack(int capacity) +// { +// this->capacity = capacity; +// this->arr = new int[capacity]; +// this->top = -1; +// }; +// ~ArrayStack() { +// delete[] arr; +// } +// void push(const int &x) { +// arr[top+1] = x; +// top += 1; +// } +// int pop() { +// if(!this->empty()) { +// int a = arr[top]; +// top -= 1; +// return a; +// } +// else { +// throw out_of_range(""); +// } +// } +// int peak() const { +// if(!this->empty()) { +// return arr[top]; +// } +// else { +// throw out_of_range(""); +// } +// } +// bool empty() const { +// if (top == -1) { +// return true; +// } +// else { +// return false; +// } +// } +// int size() const { +// return top+1; +// } +// }; + +// int main() { +// ArrayStack stack(10); +// stack.push(10); +// stack.push(20); +// stack.push(30); +// std::cout << "Top: " << stack.peak() << std::endl; +// std::cout << "Pop: " << stack.pop() << std::endl; +// std::cout << "Size: " << stack.size() << std::endl; +// return 0; +// } +// stack은 배열을 통해 구현가능 +// Node를 통해서도 구현가능 +// queue도 배열과 node를 통해서 구현가능 + +// struct Node { +// int data; +// Node *next; + +// Node(int value) :data(value), next(nullptr) {} +// }; + +// class LinkedQueue { +// private: +// Node *front; +// Node *rear; +// int currentSize; +// public: +// LinkedQueue() { +// currentSize = 0; +// front = nullptr; +// rear = nullptr; +// } +// ~LinkedQueue(); +// void enqueue(int x) { +// if(front == nullptr) { +// Node node(x); +// front = &node; +// rear = &node; +// currentSize++; +// } +// else { +// rear = rear->next; +// rear->data = x; +// currentSize++; +// } +// } +// int dequeue() { +// Node *temp = front; +// front = nullptr; +// while(this->rear->next == this->front) { +// front = rear->next; +// } +// currentSize--; +// return temp->data; +// } +// int frontElement() const { +// return front->data; +// } +// int backElement() const { +// return rear->data; +// } +// bool empty() const { +// return front == nullptr; +// } +// int size() const { +// return currentSize; +// } +// }; \ No newline at end of file diff --git a/w1/test.exe b/w1/test.exe new file mode 100644 index 0000000..24efdc0 Binary files /dev/null and b/w1/test.exe differ diff --git a/w1/test.ilk b/w1/test.ilk new file mode 100644 index 0000000..48292b0 Binary files /dev/null and b/w1/test.ilk differ diff --git a/w1/test.obj b/w1/test.obj new file mode 100644 index 0000000..98e33f1 Binary files /dev/null and b/w1/test.obj differ diff --git a/w1/test.pdb b/w1/test.pdb new file mode 100644 index 0000000..1053087 Binary files /dev/null and b/w1/test.pdb differ diff --git a/w1/vc140.pdb b/w1/vc140.pdb new file mode 100644 index 0000000..b430aca Binary files /dev/null and b/w1/vc140.pdb differ diff --git a/w2/w2.cpp b/w2/w2.cpp index e69de29..ade7861 100644 --- a/w2/w2.cpp +++ b/w2/w2.cpp @@ -0,0 +1,39 @@ +#include +#include +#include +using namespace std; + +int main() { + int N; + cin >> N; + + stack s; + + while (N--) { + string cmd; + cin >> cmd; + + if (cmd == "push") { + int x; + cin >> x; + s.push(x); + } + else if (cmd == "pop") { + if (s.empty()) cout << -1 << '\n'; + else { + cout << s.top() << '\n'; + s.pop(); + } + } + else if (cmd == "size") { + cout << s.size() << '\n'; + } + else if (cmd == "empty") { + cout << s.empty() << '\n'; + } + else if (cmd == "top") { + if (s.empty()) cout << -1 << '\n'; + else cout << s.top() << '\n'; + } + } +} diff --git a/w3/vc140.pdb b/w3/vc140.pdb new file mode 100644 index 0000000..fcc100c Binary files /dev/null and b/w3/vc140.pdb differ diff --git a/w3/w3.cpp b/w3/w3.cpp index e69de29..8c204de 100644 --- a/w3/w3.cpp +++ b/w3/w3.cpp @@ -0,0 +1,170 @@ +// #include +// #include +// using namespace std; + +// class Node { +// public: +// int data; +// Node *next; +// Node *prev; +// Node(int d) { +// data = d; +// } +// }; + +// class DLL { +// private: +// Node *head; +// Node *tail; +// Node *cursor; +// int size; +// public: +// DLL() { +// head = new Node(-1); +// tail = new Node(-1); +// cursor = nullptr; +// size = 0; +// } +// void insertNext(Node *position, int data) { +// Node *newnode = new Node(data); + +// if(size == 0) { +// head->next = newnode; +// newnode->prev = head; + +// tail->prev = newnode; +// newnode->next = tail; +// } +// else { +// Node *n = position->next; + +// position->next = newnode; +// newnode->prev = position; + +// n->prev = newnode; +// newnode->next = n; +// } +// } +// void insertFront(Node *position, int data) { +// Node *newnode = new Node(data); + +// if(size == 0) { +// Node *n = head; + +// head = newnode; + +// newnode->next = n; +// n->prev = head; +// } +// else { +// Node *n = position->prev; +// position->prev = position; + +// n->next = position; +// position->prev = n; + +// n->prev = position->prev->prev; + +// } +// } +// void remove(Node *position) { +// while(cursor == position) +// } +// }; +//집가서 수정하고 실행할 것 + + +#include +using namespace std; + +struct Node { + public: + int data; + Node *next; + Node *prev; + Node(int d) { + data = d; + next = nullptr; + prev = nullptr; + } +}; + +class CircularList { + private: + Node *cursor; + int n; + + public: + CircularList() + : cursor{nullptr}, n{0} {} + + void append(int a) { + Node *newNode = new Node(a); + + if(cursor == nullptr) { + this->cursor = newNode; + newNode->next = newNode; + newNode->prev = newNode; + } + else { + Node *last = cursor->prev; + + newNode->next = cursor; + newNode->prev = last; + + last->next = newNode; + cursor->prev = newNode; + + + } + n++; + } + + int remove() { + int data = cursor->data; + if(n==1) { + cursor = nullptr; + } + else { + Node *toRemove = cursor; + Node *preNode = cursor->prev; + Node *nextNode = cursor->next; + + preNode->next = nextNode; + nextNode->prev = preNode; + cursor = nextNode; + } + n--; + return data; + } + + bool isEmpty() { + return n==0; + } + + void move(int k) { + while(k--) { + cursor = cursor->next; + } + } +}; + +int main() { + int a, b; + cin >> a >> b; + int n{a}; + CircularList cl; + for(int i{1}; i <= a; i++) { + cl.append(i); + } + cout << '<'; + while(!cl.isEmpty()) { + cl.move(b-1); + cout << cl.remove(); + if(n != 1) { + cout << ", "; + } + n--; + } + cout << '>'; +} \ No newline at end of file diff --git a/w3/w3.exe b/w3/w3.exe new file mode 100644 index 0000000..9de2cf0 Binary files /dev/null and b/w3/w3.exe differ diff --git a/w3/w3.ilk b/w3/w3.ilk new file mode 100644 index 0000000..3b920c9 Binary files /dev/null and b/w3/w3.ilk differ diff --git a/w3/w3.obj b/w3/w3.obj new file mode 100644 index 0000000..c538fbc Binary files /dev/null and b/w3/w3.obj differ diff --git a/w3/w3.pdb b/w3/w3.pdb new file mode 100644 index 0000000..bdfc5d7 Binary files /dev/null and b/w3/w3.pdb differ diff --git a/w4/w4.cpp b/w4/w4.cpp index e69de29..c325521 100644 --- a/w4/w4.cpp +++ b/w4/w4.cpp @@ -0,0 +1,62 @@ +#include +using namespace std; + +struct Node { + char data; + Node* left; + Node* right; + + Node(char d) : data(d), left(nullptr), right(nullptr) {} +}; + +Node* nodes[26]; // A~Z 노드 저장 + +void preorder(Node* cur) { + if (cur == nullptr) return; + cout << cur->data; + preorder(cur->left); + preorder(cur->right); +} + +void middleorder(Node* cur) { + if (cur == nullptr) return; + middleorder(cur->left); + cout << cur->data; + middleorder(cur->right); +} + +void postorder(Node* cur) { + if (cur == nullptr) return; + postorder(cur->left); + postorder(cur->right); + cout << cur->data; +} + +int main() { + int N; + cin >> N; + + for (int i = 0; i < 26; i++) { + nodes[i] = new Node(char('A' + i)); + } + + for (int i = 0; i < N; i++) { + char p, l, r; + cin >> p >> l >> r; + + Node* parent = nodes[p - 'A']; + + if (l != '.') + parent->left = nodes[l - 'A']; + if (r != '.') + parent->right = nodes[r - 'A']; + } + + preorder(nodes[0]); + cout << '\n'; + middleorder(nodes[0]); + cout << '\n'; + postorder(nodes[0]); + + return 0; +}