diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..2f304eb --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,28 @@ +{ + "tasks": [ + { + "type": "cppbuild", + "label": "C/C++: cl.exe 활성 파일 빌드", + "command": "cl.exe", + "args": [ + "/Zi", + "/EHsc", + "/nologo", + "/Fe${fileDirname}\\${fileBasenameNoExtension}.exe", + "${file}" + ], + "options": { + "cwd": "${fileDirname}" + }, + "problemMatcher": [ + "$msCompile" + ], + "group": { + "kind": "build", + "isDefault": true + }, + "detail": "디버거에서 생성된 작업입니다." + } + ], + "version": "2.0.0" +} \ No newline at end of file diff --git a/w1/README.md b/w1/README.md index 92e5ce4..9c9e7fe 100644 --- a/w1/README.md +++ b/w1/README.md @@ -1 +1,4 @@ 여기에 1주차 과제를 작성해주시면 됩니다! + + +2-1 자료구조 강의를 정복하기 위한 지식을 배우고 싶습니다. \ No newline at end of file diff --git a/w1/test.exe b/w1/test.exe new file mode 100644 index 0000000..561893a 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..8edfd9f 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..8e2f153 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..5797615 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..da2723d Binary files /dev/null and b/w1/vc140.pdb differ diff --git a/w2/w2.cpp b/w2/w2.cpp index e69de29..26bc884 100644 --- a/w2/w2.cpp +++ b/w2/w2.cpp @@ -0,0 +1,77 @@ +#include +#include +using namespace std; + +class Stack { +private: + int* arr; + int top; + int size; +public: + Stack(int size) + : size{ size }, top{ -1 } { + arr = new int[size]; + } + ~Stack() { + delete[] arr; + } + void push(int x) { + if (top + 1 < size) { + arr[++top] = x; + } + else { + cout << "용량 초과"; + return; + } + } + int pop() { + if (empty()) { + return -1; + } + else { + return arr[top--]; + } + } + int gettop() const { + if (empty()) { + return -1; + } + else { + return arr[top]; + } + } + bool empty() const { + if (top == -1) + return 1; + else + return 0; + } + int getsize() const { + return top + 1; + } +}; +void stackc(string fun,Stack& stack) { + if (fun == "push") { + int x; + cin >> x; + stack.push(x); + } + else if (fun == "top") + cout<> x; + Stack stack(x); + for (int i = 0; i < x; i++) { + string y; + cin >> y; + stackc(y, stack); + } +} \ No newline at end of file diff --git a/w4/w4.cpp b/w4/w4.cpp index e69de29..96e712e 100644 --- a/w4/w4.cpp +++ b/w4/w4.cpp @@ -0,0 +1,86 @@ +#include +using namespace std; + +class Node +{ +public: + char data; + Node* parent; + Node* right; + Node* left; + + Node(); + Node(char data) : data{ data }, parent{ nullptr }, right{ nullptr }, left{ nullptr } {} + ~Node() { + delete right; + delete left; + } + void addright(Node* x) { + right = x; + right->parent = this; + + } + void addleft(Node* x) { + left = x; + left->parent = this; + } +}; +class Tree { +private: + Node* root; +public: + Tree() : root{ nullptr } {} + ~Tree() { delete root; } + Node* getroot() { return root; } + Node* findNode(Node* x, char y) { + if (x == nullptr) + return nullptr; + if (x->data == y) + return x; + Node* f = findNode(x->left, y); + if (f) + return f; + return findNode(x->right, y); + } + void setTree(char a, char b, char c) { + if (root == nullptr) { + root = new Node(a); + } + Node* p = findNode(root, a); + if (b != '.') p->addleft(new Node(b)); + if (c != '.') p->addright(new Node(c)); + } + void preorder(Node* n) { + if (n == nullptr) return; + cout << n->data; + preorder(n->left); + preorder(n->right); + } + void inorder(Node* n) { + if (n == nullptr) return; + inorder(n->left); + cout << n->data; + inorder(n->right); + } + void postorder(Node* n) { + if (n == nullptr) return; + postorder(n->left); + postorder(n->right); + cout << n->data; + } +}; + +int main() { + int n; + cin >> n; + Tree tree; + for (int i = 0; i < n; i++) { + char a, b, c; + cin >> a >> b >> c; + tree.setTree(a, b, c); + } + Node* root = tree.getroot(); + tree.preorder(root); cout << endl; + tree.inorder(root); cout << endl; + tree.postorder(root); cout << endl; +} \ No newline at end of file