인원 : 4명
일시 : 2017년 07월 14일 금요일 / 14:00 ~ 17:00
장소 : 베네핏21 / 서울 동작구 만양로14가길 32
- 진행 순서 -
1. 파이썬 기초 복습
2. 파이썬 기초 공부
3. 예제 풀이
- 내용 정리 -
1. 스택
2. 큐
< 스택 (Stack) >
데이터 입출력이 한쪽으로만 접근할 수 있는 자료 구조
LIFO (Last In First Out) 구조
언제나 최상단 데이터를 넣고 뺀다.
PUSH - 데이터를 스택에 넣는다.
POP - 데이터를 스택에서 뺀다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | def push(list, data) : list.append(data) def pop(list) : if (len(list) == 0) : print(-1) else : temp = list[len(list ? 1)] del list[len(list) - 1] print(temp) def size(list) : print(len(list)) def empty(list) : if (len(list) == 0) : print(1) else : print(0) def top(list) : if (len(list) == 0) : print(?1) else : print(list[len(list) - 1]) stack = [] num = input (“명령 횟수를 입력해주세요 : ”) for I in range(num) : script = input(“명령을 입력해주세요 : ”) if (script == “push”) : data = input(“삽입할 DATA를 입력해주세요 : ”) push(stack, data) elif (script == “pop”) : pop(stack) elif (script = “size”) : size(stack) elif (script = “empty”) : empty(stack) elif (script = “top”) : top(stack) else : print(“Error”) break | cs |
< 큐 (Queue) >
데이터 입출력이 양쪽으로 접근할 수 있는 자료 구조
FIFO (First In First Out) 구조
언제나 한쪽으로는 넣기만 하고 다른 한쪽으로는 빼기만 한다.
PUT - 데이터를 큐에 넣는다.
GET - 데이터를 큐에서 뺀다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | def push(list, data) : list.append(data) def pop(list) : if (len(list) == 0) : print(-1) else : temp = list[0] del list[0] print(temp) def size(list) : print (len(list)) def empty(list) : if (len(list) == 0) : print(1) else : print(0) def front(list) : if (len(list) == 0) : print(-1) else : print(list[0]) def back(list) : if (len(list) == 0) : print(?1) else : print(list[len(list) - 1]) queue = [] num = input (“명령 횟수를 입력해주세요 : ”) for I in range(num) : script = input(“명령을 입력해주세요 : ”) if (script == “push”) : data = input(“삽입할 DATA를 입력해주세요 : ”) push(queue, data) elif (script == “pop”) : pop(queue) elif (script = “size”) : size(queue) elif (script = “empty”) : empty(queue) elif (script = “front”) : front(queue) elif (script = “back”) : back(queue) else : print(“Error”) break | cs |