taitoss.com · Web view타이토스(Taitoss) - 고성능 블록체인 기술 스택(stack) 버전 1.0에 기초하여 관광산업에 적용된 분산형 애플리케이션의 사례
[SOPT] 데이터 구조 및 알고리즘 스터디 - #02 : 스택, 큐, 수식 연산
-
Upload
sopt-shout-our-passion-together -
Category
Software
-
view
836 -
download
0
Transcript of [SOPT] 데이터 구조 및 알고리즘 스터디 - #02 : 스택, 큐, 수식 연산
![Page 1: [SOPT] 데이터 구조 및 알고리즘 스터디 - #02 : 스택, 큐, 수식 연산](https://reader034.fdocument.pub/reader034/viewer/2022042507/587992701a28ab95318b5d95/html5/thumbnails/1.jpg)
1 0 1 0 1 0 1 0 1 0 1 0 0 0 0 0
0 1 0 1 0 1 0 1 0 1 0 1 0 0 0 1
0 1 0 1 0 1 0 1 0 0 1 0 1 0 1 0
1 0 1 0 1 0 1 0 1 0 1 0 0 1 0 1
DATA STRUCTURES
@Override
public void add(Node<T> node) {
Node pointer = header;
while (pointer.next != null) {
pointer = pointer.next;}pointer.next = node;
size++;}
스택 · 큐 · 수식연산
A
B
H
G
front
rear
![Page 2: [SOPT] 데이터 구조 및 알고리즘 스터디 - #02 : 스택, 큐, 수식 연산](https://reader034.fdocument.pub/reader034/viewer/2022042507/587992701a28ab95318b5d95/html5/thumbnails/2.jpg)
TABLE OF CONTENTS
SHOUT OUR PASSION TOGETHER DATA STRUCTURES INDEX
004
005
006
007
008
023
024
025
026
035
037
스택 - 개요
스택 - 연산
스택 - 코드 분석
스택 - 사례
스택 – 사례 : 시스템 스택
큐 - 개요
큐 - 연산
큐 - 코드 분석
큐 – 응용 : 환형 큐
큐 – 사례
수식연산
![Page 3: [SOPT] 데이터 구조 및 알고리즘 스터디 - #02 : 스택, 큐, 수식 연산](https://reader034.fdocument.pub/reader034/viewer/2022042507/587992701a28ab95318b5d95/html5/thumbnails/3.jpg)
스택개요 · 연산 · 코드 분석 · 사례
![Page 4: [SOPT] 데이터 구조 및 알고리즘 스터디 - #02 : 스택, 큐, 수식 연산](https://reader034.fdocument.pub/reader034/viewer/2022042507/587992701a28ab95318b5d95/html5/thumbnails/4.jpg)
Study - Data Structures
스택개요
스택프레임, 브라우저 히스토리구현하는데용이함
데이터입출력이제한적인이뤄지는 선형자료구조
후입선출형자료구조 - LIFO : Last In First Out
![Page 5: [SOPT] 데이터 구조 및 알고리즘 스터디 - #02 : 스택, 큐, 수식 연산](https://reader034.fdocument.pub/reader034/viewer/2022042507/587992701a28ab95318b5d95/html5/thumbnails/5.jpg)
Study - Data Structures
스택연산
Lollipop
Kitkat
Jellybean
Ice Cream Sandwich
Marshmallow
Lollipop
Kitkat
Jellybean
Ice Cream Sandwich
Lollipop
Kitkat
Jellybean
Ice Cream Sandwich
Marshmallow
push(‘Marshmallow’) pop()
top() : return ‘Marshmallow’
![Page 6: [SOPT] 데이터 구조 및 알고리즘 스터디 - #02 : 스택, 큐, 수식 연산](https://reader034.fdocument.pub/reader034/viewer/2022042507/587992701a28ab95318b5d95/html5/thumbnails/6.jpg)
스택코드분석
Study - Data Structures
public class Stack<T> extends Collection<T> {
private LinkedList<T> list = new LinkedList<T>();
public void push(Node<T> node) {
list.add(node);size++;
}
public Node<T> pop() {
if (size == 0)return null;
return list.remove(--size);}
@Overridepublic Node<T> get(int index) {
return list.get(index); }
}
이전에구현한 연결리스트를 활용하여구현
추가 | 제거는 연결리스트의 말단에서이뤄짐
![Page 7: [SOPT] 데이터 구조 및 알고리즘 스터디 - #02 : 스택, 큐, 수식 연산](https://reader034.fdocument.pub/reader034/viewer/2022042507/587992701a28ab95318b5d95/html5/thumbnails/7.jpg)
Study - Data Structures
스택사례
알고리즘 브라우저이력 관리 시스템스택
http://sopt.org
…
Prev. SFP
Return Address
Parameters +
Local Variables
![Page 8: [SOPT] 데이터 구조 및 알고리즘 스터디 - #02 : 스택, 큐, 수식 연산](https://reader034.fdocument.pub/reader034/viewer/2022042507/587992701a28ab95318b5d95/html5/thumbnails/8.jpg)
Study - Data Structures
스택사례 -시스템스택
-
Parameters +
Local Variables
SFP₁ : Stack Frame Pointer
RA₁ : Return Address
…
-
Parameters+
Local Variables
SFP₂
RA₂
Parameters+
Local Variables
SFP₁
RA₁
…
돌아갈주소를저장 – Code 영역
메서드호출 메서드종료
위의 그림은 Stack 영역 을 표현한 것이며, Return Address가저장하는 내용은 Code 영역 의 주소임
-
Parameters +
Local Variables
SFP₁
RA₁
…
![Page 9: [SOPT] 데이터 구조 및 알고리즘 스터디 - #02 : 스택, 큐, 수식 연산](https://reader034.fdocument.pub/reader034/viewer/2022042507/587992701a28ab95318b5d95/html5/thumbnails/9.jpg)
Study - Data Structures
스택사례 -시스템스택
main :
int a = 10;
printf("a: %d\n", a);
foo();
return;
foo :
int a = 20;
printf("a: %d\n", a);
bar(a);
bar :
printf("a: %d\n", a);
addr
0x010
0x011
0x012
0x013
0x014
0x015
0x016
0x017
0x018
0x019
0x020
#include <stdio.h>
void bar(int a) {
printf("a: %d\n", a);}
void foo() {
int a = 20;printf("a: %d\n", a);
bar(a);}
int main() {
int a = 10;printf("a: %d\n", a);
foo();
return 0;}
![Page 10: [SOPT] 데이터 구조 및 알고리즘 스터디 - #02 : 스택, 큐, 수식 연산](https://reader034.fdocument.pub/reader034/viewer/2022042507/587992701a28ab95318b5d95/html5/thumbnails/10.jpg)
Study - Data Structures
스택사례 -시스템스택
코드영역 스택영역
실행할프로그램의코드가저장되는영역 파라미터, 로컬변수가저장되는영역
main :
int a = 10;
printf("a: %d\n", a);
foo();
return;
foo :
int a = 20;
printf("a: %d\n", a);
bar(a);
bar :
printf("a: %d\n", a);
addr
0x010
0x011
0x012
0x013
0x014
0x015
0x016
0x017
0x018
0x019
0x020 0xA48NULL
addr
![Page 11: [SOPT] 데이터 구조 및 알고리즘 스터디 - #02 : 스택, 큐, 수식 연산](https://reader034.fdocument.pub/reader034/viewer/2022042507/587992701a28ab95318b5d95/html5/thumbnails/11.jpg)
Study - Data Structures
스택사례 -시스템스택
코드영역 스택영역
실행할프로그램의코드가저장되는영역 파라미터, 로컬변수가저장되는영역
main :
int a = 10;
printf("a: %d\n", a);
foo();
return;
foo :
int a = 20;
printf("a: %d\n", a);
bar(a);
bar :
printf("a: %d\n", a);
addr
0x010
0x011
0x012
0x013
0x014
0x015
0x016
0x017
0x018
0x019
0x020
0xA49
0xA48
main.a - 10
NULL
addr
![Page 12: [SOPT] 데이터 구조 및 알고리즘 스터디 - #02 : 스택, 큐, 수식 연산](https://reader034.fdocument.pub/reader034/viewer/2022042507/587992701a28ab95318b5d95/html5/thumbnails/12.jpg)
Study - Data Structures
스택사례 -시스템스택
코드영역 스택영역
실행할프로그램의코드가저장되는영역 파라미터, 로컬변수가저장되는영역
main :
int a = 10;
printf("a: %d\n", a);
foo();
return;
foo :
int a = 20;
printf("a: %d\n", a);
bar(a);
bar :
printf("a: %d\n", a);
addr
0x010
0x011
0x012
0x013
0x014
0x015
0x016
0x017
0x018
0x019
0x020
0xA49
0xA48
main.a - 10
NULL
addr
![Page 13: [SOPT] 데이터 구조 및 알고리즘 스터디 - #02 : 스택, 큐, 수식 연산](https://reader034.fdocument.pub/reader034/viewer/2022042507/587992701a28ab95318b5d95/html5/thumbnails/13.jpg)
Study - Data Structures
스택사례 -시스템스택
코드영역 스택영역
실행할프로그램의코드가저장되는영역 파라미터, 로컬변수가저장되는영역
main :
int a = 10;
printf("a: %d\n", a);
foo();
return;
foo :
int a = 20;
printf("a: %d\n", a);
bar(a);
bar :
printf("a: %d\n", a);
addr
0x010
0x011
0x012
0x013
0x014
0x015
0x016
0x017
0x018
0x019
0x020
0xA50
0xA49
0xA48
SFP₁ : 0xA49
RA₁ : 0x013
main.a - 10
NULL
0xA51
addr
![Page 14: [SOPT] 데이터 구조 및 알고리즘 스터디 - #02 : 스택, 큐, 수식 연산](https://reader034.fdocument.pub/reader034/viewer/2022042507/587992701a28ab95318b5d95/html5/thumbnails/14.jpg)
Study - Data Structures
스택사례 -시스템스택
코드영역 스택영역
실행할프로그램의코드가저장되는영역 파라미터, 로컬변수가저장되는영역
main :
int a = 10;
printf("a: %d\n", a);
foo();
return;
foo :
int a = 20;
printf("a: %d\n", a);
bar(a);
bar :
printf("a: %d\n", a);
addr
0x010
0x011
0x012
0x013
0x014
0x015
0x016
0x017
0x018
0x019
0x020
0xA52
0xA50
0xA49
0xA48
foo.a - 20
SFP₁ : 0xA49
RA₁ : 0x013
main.a - 10
NULL
0xA51
addr
![Page 15: [SOPT] 데이터 구조 및 알고리즘 스터디 - #02 : 스택, 큐, 수식 연산](https://reader034.fdocument.pub/reader034/viewer/2022042507/587992701a28ab95318b5d95/html5/thumbnails/15.jpg)
Study - Data Structures
스택사례 -시스템스택
코드영역 스택영역
실행할프로그램의코드가저장되는영역 파라미터, 로컬변수가저장되는영역
main :
int a = 10;
printf("a: %d\n", a);
foo();
return;
foo :
int a = 20;
printf("a: %d\n", a);
bar(a);
bar :
printf("a: %d\n", a);
addr
0x010
0x011
0x012
0x013
0x014
0x015
0x016
0x017
0x018
0x019
0x020
0xA52
0xA50
0xA49
0xA48
foo.a - 20
SFP₁ : 0xA49
RA₁ : 0x013
main.a - 10
NULL
0xA51
addr
![Page 16: [SOPT] 데이터 구조 및 알고리즘 스터디 - #02 : 스택, 큐, 수식 연산](https://reader034.fdocument.pub/reader034/viewer/2022042507/587992701a28ab95318b5d95/html5/thumbnails/16.jpg)
Study - Data Structures
스택사례 -시스템스택
코드영역 스택영역
실행할프로그램의코드가저장되는영역 파라미터, 로컬변수가저장되는영역
main :
int a = 10;
printf("a: %d\n", a);
foo();
return;
foo :
int a = 20;
printf("a: %d\n", a);
bar(a);
bar :
printf("a: %d\n", a);
addr
0x010
0x011
0x012
0x013
0x014
0x015
0x016
0x017
0x018
0x019
0x020
0xA53
0xA52
0xA50
0xA49
0xA48
SFP₂ : 0xA50
RA₂ : 0x018
foo.a - 20
SFP₁ : 0xA49
RA₁ : 0x013
main.a - 10
NULL
0xA54
0xA51
addr
![Page 17: [SOPT] 데이터 구조 및 알고리즘 스터디 - #02 : 스택, 큐, 수식 연산](https://reader034.fdocument.pub/reader034/viewer/2022042507/587992701a28ab95318b5d95/html5/thumbnails/17.jpg)
Study - Data Structures
스택사례 -시스템스택
코드영역 스택영역
실행할프로그램의코드가저장되는영역 파라미터, 로컬변수가저장되는영역
main :
int a = 10;
printf("a: %d\n", a);
foo();
return;
foo :
int a = 20;
printf("a: %d\n", a);
bar(a);
bar :
printf("a: %d\n", a);
addr
0x010
0x011
0x012
0x013
0x014
0x015
0x016
0x017
0x018
0x019
0x020
addr
0xA55
0xA53
0xA52
0xA50
0xA49
0xA48
bar.a - 20
SFP₂ : 0xA50
RA₂ : 0x018
foo.a - 20
SFP₁ : 0xA49
RA₁ : 0x013
main.a - 10
NULL
0xA54
0xA51
![Page 18: [SOPT] 데이터 구조 및 알고리즘 스터디 - #02 : 스택, 큐, 수식 연산](https://reader034.fdocument.pub/reader034/viewer/2022042507/587992701a28ab95318b5d95/html5/thumbnails/18.jpg)
Study - Data Structures
스택사례 -시스템스택
코드영역 스택영역
실행할프로그램의코드가저장되는영역 파라미터, 로컬변수가저장되는영역
main :
int a = 10;
printf("a: %d\n", a);
foo();
return;
foo :
int a = 20;
printf("a: %d\n", a);
bar(a);
bar :
printf("a: %d\n", a);
addr
0x010
0x011
0x012
0x013
0x014
0x015
0x016
0x017
0x018
0x019
0x020
addr
0xA55
0xA53
0xA52
0xA50
0xA49
0xA48
bar.a - 20
SFP₂ : 0xA50
RA₂ : 0x018
foo.a - 20
SFP₁ : 0xA49
RA₁ : 0x013
main.a - 10
NULL
0xA54
0xA51
![Page 19: [SOPT] 데이터 구조 및 알고리즘 스터디 - #02 : 스택, 큐, 수식 연산](https://reader034.fdocument.pub/reader034/viewer/2022042507/587992701a28ab95318b5d95/html5/thumbnails/19.jpg)
Study - Data Structures
스택사례 -시스템스택
코드영역 스택영역
실행할프로그램의코드가저장되는영역 파라미터, 로컬변수가저장되는영역
main :
int a = 10;
printf("a: %d\n", a);
foo();
return;
foo :
int a = 20;
printf("a: %d\n", a);
bar(a);
bar :
printf("a: %d\n", a);
addr
0x010
0x011
0x012
0x013
0x014
0x015
0x016
0x017
0x018
0x019
0x020
0xA52
0xA50
0xA49
0xA48
foo.a - 20
SFP₁ : 0xA49
RA₁ : 0x013
main.a - 10
NULL
0xA51
addr
![Page 20: [SOPT] 데이터 구조 및 알고리즘 스터디 - #02 : 스택, 큐, 수식 연산](https://reader034.fdocument.pub/reader034/viewer/2022042507/587992701a28ab95318b5d95/html5/thumbnails/20.jpg)
Study - Data Structures
스택사례 -시스템스택
코드영역 스택영역
실행할프로그램의코드가저장되는영역 파라미터, 로컬변수가저장되는영역
main :
int a = 10;
printf("a: %d\n", a);
foo();
return;
foo :
int a = 20;
printf("a: %d\n", a);
bar(a);
bar :
printf("a: %d\n", a);
addr
0x010
0x011
0x012
0x013
0x014
0x015
0x016
0x017
0x018
0x019
0x020
0xA49
0xA48
main.a - 10
NULL
addr
![Page 21: [SOPT] 데이터 구조 및 알고리즘 스터디 - #02 : 스택, 큐, 수식 연산](https://reader034.fdocument.pub/reader034/viewer/2022042507/587992701a28ab95318b5d95/html5/thumbnails/21.jpg)
Study - Data Structures
스택사례 -시스템스택
코드영역 스택영역
실행할프로그램의코드가저장되는영역 파라미터, 로컬변수가저장되는영역
main :
int a = 10;
printf("a: %d\n", a);
foo();
return;
foo :
int a = 20;
printf("a: %d\n", a);
bar(a);
bar :
printf("a: %d\n", a);
addr
0x010
0x011
0x012
0x013
0x014
0x015
0x016
0x017
0x018
0x019
0x020 0xA48NULL
addr
![Page 22: [SOPT] 데이터 구조 및 알고리즘 스터디 - #02 : 스택, 큐, 수식 연산](https://reader034.fdocument.pub/reader034/viewer/2022042507/587992701a28ab95318b5d95/html5/thumbnails/22.jpg)
큐개요 · 연산 · 코드 분석 · 응용 · 사례
![Page 23: [SOPT] 데이터 구조 및 알고리즘 스터디 - #02 : 스택, 큐, 수식 연산](https://reader034.fdocument.pub/reader034/viewer/2022042507/587992701a28ab95318b5d95/html5/thumbnails/23.jpg)
Study - Data Structures
큐개요
스케쥴러, 네트워크요청 대기열구현에용이함
입력순서와출력순서가 일치하는자료구조
선입선출형자료구조 - FIFO : First In First Out
IN OUT
![Page 24: [SOPT] 데이터 구조 및 알고리즘 스터디 - #02 : 스택, 큐, 수식 연산](https://reader034.fdocument.pub/reader034/viewer/2022042507/587992701a28ab95318b5d95/html5/thumbnails/24.jpg)
Study - Data Structures
큐연산
BANANA
CARROT
DURIAN
EGG
PLANT
FIG
APPLE
enqueue(‘FIG’)
FIG
APPLE
dequeue(‘APPLE’)
![Page 25: [SOPT] 데이터 구조 및 알고리즘 스터디 - #02 : 스택, 큐, 수식 연산](https://reader034.fdocument.pub/reader034/viewer/2022042507/587992701a28ab95318b5d95/html5/thumbnails/25.jpg)
큐코드분석 -연결리스트를이용한큐의구현
Study - Data Structures
public class Queue<T> extends Collection<T> {
private LinkedList<T> list = new LinkedList<T>();
public void enqueue(Node<T> node) {
list.add(node);size++;
}
public Node<T> dequeue() {
if (size == 0)return null;
Node<T> node = list.remove(0);size--;
return node;}
@Overridepublic Node<T> get(int index) {
return list.get(index); }
}
이전에구현한 연결리스트를 활용하여구현
추가 | 삭제는 연결리스트의 머리 | 말단에서이뤄짐
![Page 26: [SOPT] 데이터 구조 및 알고리즘 스터디 - #02 : 스택, 큐, 수식 연산](https://reader034.fdocument.pub/reader034/viewer/2022042507/587992701a28ab95318b5d95/html5/thumbnails/26.jpg)
Study - Data Structures
큐응용 -환형큐
A
B
H
G
front
rear
C
D
E
F mod 연산으로선형의배열을환형으로 이해하고구현
front, rear 포인터로큐의앞과뒤를구분
배열로큐를구현할때의 한계를개선하기위한형태
![Page 27: [SOPT] 데이터 구조 및 알고리즘 스터디 - #02 : 스택, 큐, 수식 연산](https://reader034.fdocument.pub/reader034/viewer/2022042507/587992701a28ab95318b5d95/html5/thumbnails/27.jpg)
큐코드분석 -배열을이용한환형큐의구현
Study - Data Structures
public class CircularQueue<T> {
private int capacity;
private int front;private int rear;
private Class<T> c;private T[] array;
public CircularQueue (Class<T> c, int capacity) { … }
public void enqueue(T t) { … }public T dequeue() { … }
public T get(int index) { … }public int size() { … }public boolean isEmpty() { … }
}
큐의크기와 큐의전방 | 후방위치에대한 변수정의
제너릭타입 배열선언을 위한 Class 타입 저장
요소추가, 삭제, 크기반환에 대한동작정의
특정위치 요소반환, 비어있는지확인하는 동작정의
![Page 28: [SOPT] 데이터 구조 및 알고리즘 스터디 - #02 : 스택, 큐, 수식 연산](https://reader034.fdocument.pub/reader034/viewer/2022042507/587992701a28ab95318b5d95/html5/thumbnails/28.jpg)
큐코드분석 -배열을이용한환형큐의구현
Study - Data Structures
타입과크기를 저장하여관리
Java에서 제너릭 타입의배열을 선언하는방식
public class CircularQueue<T> {
…
public CircularQueue (Class<T> c, int capacity) {
this.c = c;this.capacity = capacity;this.array = (T []) Array.newInstance(c, capacity);
}
…
public T dequeue() {
front = (front + 1) % capacity;return array[front];
}
public T get(int index) {
return array[(front + 1 + index) % capacity];}
public int size() {
return Math.abs(rear - (front + 1) % capacity + 1);}
public boolean isEmpty() { return front == rear; }}
front를 한칸당겨 큐에서제거하고 요소를반환
환형큐이므로 MOD 연산처리하여 예외사항을방지
front를 기준으로찾고자하는요소를 반환
front ~ rear의 간격을기준으로 요소갯수를 반환
front = rear이면 큐에요소가 없음을의미함
![Page 29: [SOPT] 데이터 구조 및 알고리즘 스터디 - #02 : 스택, 큐, 수식 연산](https://reader034.fdocument.pub/reader034/viewer/2022042507/587992701a28ab95318b5d95/html5/thumbnails/29.jpg)
큐
Study - Data Structures
큐가가득찼을 경우, 큐를 2배로확장하는코드
원래크기의 2배에해당하는임시 배열선언
public class CircularQueue<T> {…public void enqueue(T t) {
if ((rear + 1) % capacity == front) {T[] newArray =
(T []) Array.newInstance(c, 2 * capacity);
int start = (front + 1) % capacity;if (start < 2) {
System.arraycopy(array, start, newArray, 0, rear - start + 1);
}else {
System.arraycopy(array, start, newArray, capacity, capacity);
System.arraycopy(array, 0, newArray, capacity - start, rear + 1);
}front = 2 * capacity - 1;rear = capacity - 2;capacity *= 2;array = newArray;
}
rear = (rear + 1) % capacity;array[rear] = t;
}…
}
시작위치가 2 미만일경우, 임시배열에 바로추가
시작위치가 2 이상일경우, 기존데이터를임시배열의 처음과끝에 나누어복사해야함
front | rear의 위치를조정
실제로신규 요소가추가하는 동작
코드분석 -배열을이용한환형큐의구현
크기에대한 값을 2배로늘리고 임시배열을할당
![Page 30: [SOPT] 데이터 구조 및 알고리즘 스터디 - #02 : 스택, 큐, 수식 연산](https://reader034.fdocument.pub/reader034/viewer/2022042507/587992701a28ab95318b5d95/html5/thumbnails/30.jpg)
큐
Study - Data Structures
코드분석 -배열을이용한환형큐의구현
? ? ? ? ? ? ? ?
origin
temp
a b c
front rearstart
? ?
d
Q. ‘start - 요소가시작하는위치’가 2 미만일경우는어떻게복사해야하는가 ?
![Page 31: [SOPT] 데이터 구조 및 알고리즘 스터디 - #02 : 스택, 큐, 수식 연산](https://reader034.fdocument.pub/reader034/viewer/2022042507/587992701a28ab95318b5d95/html5/thumbnails/31.jpg)
큐
Study - Data Structures
코드분석 -배열을이용한환형큐의구현
a b c d e ? ? ?
origin
temp
a b c
front
front
start
? ?
d
Q. ‘start - 요소가시작하는위치’가 2 미만일경우는어떻게복사해야하는가 ?
A.이미요소가 origin 배열에순차적으로있기때문에 temp에 순서대로복사하면된다
rearstart
![Page 32: [SOPT] 데이터 구조 및 알고리즘 스터디 - #02 : 스택, 큐, 수식 연산](https://reader034.fdocument.pub/reader034/viewer/2022042507/587992701a28ab95318b5d95/html5/thumbnails/32.jpg)
큐
Study - Data Structures
코드분석 -배열을이용한환형큐의구현
? ? ? ? ? ? ? ?
origin
temp
b c d
? ?
a
startfrontrear
Q. ‘start - 요소가시작하는위치’가 2 이상일경우는어떻게복사해야하는가 ?
![Page 33: [SOPT] 데이터 구조 및 알고리즘 스터디 - #02 : 스택, 큐, 수식 연산](https://reader034.fdocument.pub/reader034/viewer/2022042507/587992701a28ab95318b5d95/html5/thumbnails/33.jpg)
큐
Study - Data Structures
코드분석 -배열을이용한환형큐의구현
a b c d e ? ? ?
origin
temp
b c d
? ?
a
startfrontrear
Q. ‘start - 요소가시작하는위치’가 2 이상일경우는어떻게복사해야하는가 ?
A. front ~ 배열끝까지의요소를먼저붙이고, 0 ~ rear에 해당하는요소를이어붙인다
frontrearstart
![Page 34: [SOPT] 데이터 구조 및 알고리즘 스터디 - #02 : 스택, 큐, 수식 연산](https://reader034.fdocument.pub/reader034/viewer/2022042507/587992701a28ab95318b5d95/html5/thumbnails/34.jpg)
큐
Study - Data Structures
코드분석 -배열을이용한환형큐의구현
a b c d e ? ? ?
origin
temp
b c d
? ?
a
startfrontrear
Q. ‘start - 요소가시작하는위치’가 2 이상일경우는어떻게복사해야하는가 ?
A. front ~ 배열끝까지의요소를먼저붙이고, 0 ~ rear에 해당하는요소를이어붙인다
frontrearstart
필요성origin의 상태와상관없이 front와 rear의 위치를손쉽게계산할 수있다
- front : 2 * capacity – 1 (신규 배열의맨마지막 위치)- rear : capacity – 2 (확장했을 때,신규 요소가들어갈위치)
![Page 35: [SOPT] 데이터 구조 및 알고리즘 스터디 - #02 : 스택, 큐, 수식 연산](https://reader034.fdocument.pub/reader034/viewer/2022042507/587992701a28ab95318b5d95/html5/thumbnails/35.jpg)
이벤트큐 작업스케쥴러 데이터버퍼
Study - Data Structures
큐사례
![Page 36: [SOPT] 데이터 구조 및 알고리즘 스터디 - #02 : 스택, 큐, 수식 연산](https://reader034.fdocument.pub/reader034/viewer/2022042507/587992701a28ab95318b5d95/html5/thumbnails/36.jpg)
수식연산개요 · 중위식 - 후위식변환 · 후위식 연산 · 코드분석
![Page 37: [SOPT] 데이터 구조 및 알고리즘 스터디 - #02 : 스택, 큐, 수식 연산](https://reader034.fdocument.pub/reader034/viewer/2022042507/587992701a28ab95318b5d95/html5/thumbnails/37.jpg)
Study - Data Structures
수식연산개요 -수식표현
중위식 : A / B - C + D x E - A x C
![Page 38: [SOPT] 데이터 구조 및 알고리즘 스터디 - #02 : 스택, 큐, 수식 연산](https://reader034.fdocument.pub/reader034/viewer/2022042507/587992701a28ab95318b5d95/html5/thumbnails/38.jpg)
Study - Data Structures
수식연산개요 -수식표현
중위식 : A / B - C + D x E - A x C후위식 : :A B / C - D E x + A C x -
![Page 39: [SOPT] 데이터 구조 및 알고리즘 스터디 - #02 : 스택, 큐, 수식 연산](https://reader034.fdocument.pub/reader034/viewer/2022042507/587992701a28ab95318b5d95/html5/thumbnails/39.jpg)
Study - Data Structures
수식연산개요 -필요성
중위식 : A / B - C + D x E - A x C후위식 : :A B / C - D E x + A C x -컴퓨터가수식 연산을하기에 훨씬편리한구조
필요성
![Page 40: [SOPT] 데이터 구조 및 알고리즘 스터디 - #02 : 스택, 큐, 수식 연산](https://reader034.fdocument.pub/reader034/viewer/2022042507/587992701a28ab95318b5d95/html5/thumbnails/40.jpg)
Study - Data Structures
수식연산중위식을후위식으로변환
‘)’일 경우,스택에 보관된 ‘(’가 나오기전까지 모두출력하고 ‘(’를 스택에서제거한다
토큰이피연산자일 경우에는바로 출력한다
모든토큰에대해서 ‘종료 - #’가나오기전까지다음사항을반복한다
연산자일경우, 스택 최상단의연산자와우선순위를 비교해서출력하거나스택에 넣는다
스택에남은연산자를모두출력한다
![Page 41: [SOPT] 데이터 구조 및 알고리즘 스터디 - #02 : 스택, 큐, 수식 연산](https://reader034.fdocument.pub/reader034/viewer/2022042507/587992701a28ab95318b5d95/html5/thumbnails/41.jpg)
Study - Data Structures
수식연산후위식연산
연산자일경우, 스택에서 피연산자를두개 꺼내서연산후 다시스택에 넣는다
토큰이피연산자일 경우에스택에 넣는다
모든토큰에대해서 ‘종료 - #’가나오기전까지다음사항을반복한다
![Page 42: [SOPT] 데이터 구조 및 알고리즘 스터디 - #02 : 스택, 큐, 수식 연산](https://reader034.fdocument.pub/reader034/viewer/2022042507/587992701a28ab95318b5d95/html5/thumbnails/42.jpg)
Study - Data Structures
수식연산코드분석
https://github.com/henlix/calculator