Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -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"
}
3 changes: 3 additions & 0 deletions w1/README.md
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
여기에 1주차 과제를 작성해주시면 됩니다!


2-1 자료구조 강의를 정복하기 위한 지식을 배우고 싶습니다.
Binary file added w1/test.exe
Binary file not shown.
Binary file added w1/test.ilk
Binary file not shown.
Binary file added w1/test.obj
Binary file not shown.
Binary file added w1/test.pdb
Binary file not shown.
Binary file added w1/vc140.pdb
Binary file not shown.
77 changes: 77 additions & 0 deletions w2/w2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#include<iostream>
#include<string>
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<<stack.gettop()<<endl;
else if (fun == "pop")
cout << stack.pop() << endl;
else if (fun == "empty")
cout << stack.empty() << endl;
else if (fun == "size")
cout << stack.getsize() << endl;
}
int main() {
int x;
cin >> x;
Stack stack(x);
for (int i = 0; i < x; i++) {
string y;
cin >> y;
stackc(y, stack);
}
}
86 changes: 86 additions & 0 deletions w4/w4.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#include<iostream>
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;
}