CS/자료구조

    Linked List

    Boundary conditions Whenever you make a data structure, you have to consider these 5 things. 1. Empty data structure 2. Single element in the data structure 3. Working at the beginning 4. Working at the end 5. Working in the middle public class Main { public static void main(String[] args) { List list = new LinkedList(); // LinkedList가 아닌 List 변수로 선언하면 // list = new ArrayList(); 와 같이 재활용이 가능해진다 ..

    Queue (Python)

    Queue (Python)

    class Queue: def __init__(self, base = []): self.__items = base self.__start = 0 #self.__end

    Stack : 계산기 (Python)

    Stack : 계산기 (Python)

    class Calculator: def __init__(self): self.expression = "" def to_postfix(self): expression_list = list(self.expression.rstrip()) stack = [] operands = list(map(str, range(10))) result = [] for token in expression_list: if token in operands: result.append(token) elif token == '(': stack.append(token) elif token == ')': while stack: popped = stack.pop() if popped == "(": break else: result.append..

    Stack (Python)

    Stack (Python)

    class Stack: def __init__(self, base = []): self.__items = base def push(self, val): self.__items.append(val) def pop(self): try: return self.__items.pop() except IndexError: print("Stack is empty") def top(self): try: return self.__items[-1] except IndexError: print("Stack is empty") def __len__(self): return len(self.__items) stack = Stack() stack.push(3) print(stack.pop()) print(f"length of s..