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++: g++ 활성 파일 빌드",
"command": "/usr/bin/g++",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "디버거에서 생성된 작업입니다."
}
],
"version": "2.0.0"
}
1 change: 1 addition & 0 deletions w1/README.md
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
여기에 1주차 과제를 작성해주시면 됩니다!
이번 강의를 통해 다음 학기에 배우게 될 자료구조에 등장하는 어려운 개념에 대해 강사님의 접근법을 사전에 배워서 다음학기에 자료구조 수업을 조금 수월하게 이수할 수 있기를 희망합니다.
Binary file added w1/test
Binary file not shown.
20 changes: 20 additions & 0 deletions w1/test.dSYM/Contents/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleIdentifier</key>
<string>com.apple.xcode.dsym.test</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
<string>dSYM</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
</dict>
</plist>
Binary file added w1/test.dSYM/Contents/Resources/DWARF/test
Binary file not shown.
5 changes: 5 additions & 0 deletions w1/test.dSYM/Contents/Resources/Relocations/aarch64/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
triple: 'arm64-apple-darwin'
binary-path: '/Users/kwakminjun/SDC-datastructure/w1/test'
relocations: []
...
67 changes: 67 additions & 0 deletions w2/w2(linkedlist).py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import sys

# 링크드 리스트 형태로 구현
class Node:
def __init__(self, data):
self.data = data
self.next = None

class LinkedStack:
def __init__(self):
self.top_node = None
self.current_size = 0

def push(self, x):
new_node = Node(x)
new_node.next = self.top_node
self.top_node = new_node
self.current_size += 1

def pop(self):
if self.empty_status():
return -1

pop_data = self.top_node.data
self.top_node = self.top_node.next
self.current_size -= 1
return pop_data

def size(self):
return self.current_size

def empty_status(self):
return self.top_node is None

def top(self):
if self.empty_status():
return -1
return self.top_node.data

def solve():
input = sys.stdin.read().splitlines()
if not input:
return

n = int(input[0])
stack = LinkedStack()
output = []

for i in range(1, n + 1):
command = input[i].split()

if command[0] == "push":
stack.push(int(command[1]))
elif command[0] == "pop":
output.append(str(stack.pop()))
elif command[0] == "size":
output.append(str(stack.size()))
elif command[0] == "empty":
# 문제 조건에 따라 비어있으면 1, 아니면 0 출력
output.append("1" if stack.empty_status() else "0")
elif command[0] == "top":
output.append(str(stack.top()))

sys.stdout.write("\n".join(output) + "\n")

if __name__ == "__main__":
solve()
56 changes: 56 additions & 0 deletions w2/w2(list).py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import sys

# 강의 자료의 배열 형태 구현
class Stack:
def __init__(self):

self.items = []

def push(self, x):

self.items.append(x)

def pop(self):
if self.empty():
return -1
return self.items.pop()

def size(self):
return len(self.items)

def empty(self):
return 1 if not self.items else 0

def top(self):
if self.empty():
return -1
return self.items[-1]


def solve():
input_data = sys.stdin.read().splitlines()
if not input_data:
return

n = int(input_data[0])
stack = Stack()
results = []

for i in range(1, n + 1):
command = input_data[i].split()

if command[0] == "push":
stack.push(int(command[1]))
elif command[0] == "pop":
results.append(str(stack.pop()))
elif command[0] == "size":
results.append(str(stack.size()))
elif command[0] == "empty":
results.append(str(stack.empty()))
elif command[0] == "top":
results.append(str(stack.top()))

sys.stdout.write("\n".join(results) + "\n")

if __name__ == "__main__":
solve()
77 changes: 77 additions & 0 deletions w4/w4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@

class Node:
def __init__(self, data):
self.data = data
self.left = None
self.right = None


class BinaryTree:
def __init__(self):
self.nodes = {}


def get_node(self, data):
if data == '.':
return None
if data not in self.nodes:
self.nodes[data] = Node(data)
return self.nodes[data]


def preorder(self, node):
if node:
print(node.data, end='')
self.preorder(node.left)
self.preorder(node.right)


def inorder(self, node):
if node:
self.inorder(node.left)
print(node.data, end='')
self.inorder(node.right)


def postorder(self, node):
if node:
self.postorder(node.left)
self.postorder(node.right)
print(node.data, end='')


def solve():
import sys

input_data = sys.stdin.read().split()
if not input_data:
return

n = int(input_data[0])
tree = BinaryTree()


idx = 1
for _ in range(n):
root_data = input_data[idx]
left_data = input_data[idx+1]
right_data = input_data[idx+2]

parent = tree.get_node(root_data)
parent.left = tree.get_node(left_data)
parent.right = tree.get_node(right_data)
idx += 3


root_node = tree.nodes['A']

# 결과
tree.preorder(root_node)
print()
tree.inorder(root_node)
print()
tree.postorder(root_node)
print()

if __name__ == "__main__":
solve()