SlideShare a Scribd company logo
SWIFT
Data Structure -
Array
Bill Kim(김정훈) | ibillkim@gmail.com
목차
•Array List
•Concept
•Features
•Implementation
•References
Array List
자료구조에서 가장 기본이 되는 구조는 배열(리스트)입니다.
리스트는 크게 아래와 같이 2개의 리스트로 구분할 수 있습니다.
순차 리스트 :
배열을 기반으로 구현된 리스트
연결 리스트 :
메모리의 동적 할당을 기반으로 구현된 리스트
본 강의에서는 Swift 코드를 활용하여 순차 리스트에 대해서 살펴
봅니다.
Concept
순차리스트는 아래와 같이 특정 자료를 정해진 공간안에서 순차적
으로 저장 및 가져오는 자료구조입니다.
Features
순차 리스트(Array)의 특징을 살펴보면 아래와 같습니다.
- 데이터를 순차적으로 저장합니다.
- 데이터 중복 저장을 허용합니다.
- 배열의 총 길이는 초기에 결정되어야 합니다.(변경 불가)
- 인덱스 값을 기준으로 데이터의 참조가 가능합니다.
- 삭제의 과정에서 데이터의 이동이 빈번하게 일어납니다.
Implementation
Swift를 활용하여 Array 를 구현해보겠습니다.
우선 필요한 메소드는 아래와 같습니다.
- init() : 배열의 크기를 설정하는 초기화 함수
- insert() : 데이터 입력
- remove() : 특정 인덱스의 데이터 삭제
- removeAll() : 모든 데이터 삭제
- get() : 특정 인덱스의 데이터 값을 반환
- count() : 현재 배열의 크기를 반환
Implementation
가장 데이터의 기본이 되는 Node 클래스 입니다.
해당 Node 클래스는 모든 데이터 형식을 받을 수 있도록
Generic 형태로 구현이 되어 있습니다.
class Node<T> {
fileprivate var data:T
init(_ data: T) {
self.data = data
}
}
Implementation
class ArrayList<T> {
private var size:Int
private var list:[Node<T>]
init(size:Int) {
self.list = [Node<T>]()
self.size = size
}
func insert(item:T) {
if self.list.count < size {
self.list.append(Node<T>(item))
}
}
func remove(at:Int) {
if self.list.count <= 0 { return }
if self.list.count <= at { return }
self.list.remove(at: at)
}
func removeAll() {
self.list.removeAll()
}
func get(index:Int) -> T {
return self.list[index].data
}
func count() -> Int {
size = list.count
return size
}
}
Implementation
아래와 같이 사용이 가능합니다.
let list:ArrayList<Int> = ArrayList(size: 5)
list.insert(item: 1)
list.insert(item: 2)
list.insert(item: 3)
list.insert(item: 4)
list.insert(item: 5)
// 최대 리스트 크기가 5로 설정하였으므로 추가 불가
list.insert(item: 6)
// 현재 리스트 카운트 : 5
print(list.count())
for i in 0..<list.count() {
print(list.get(index: i))
// 1
// 2
// 3
// 4
// 5
}
Implementation
// 4번째 요소 삭제
list.remove(at: 3)
// 현재 리스트 카운트 : 4
print(list.count())
for i in 0..<list.count() {
print(list.get(index: i))
// 1
// 2
// 3
// 5
}
list.removeAll()
// 현재 리스트 카운트 : 0
print(list.count())
References
[1] [Swift 자료구조 ch01] 자료구조 살펴보기 : https://
kor45cw.tistory.com/238
[2] Swift로 자료구조, 알고리즘 공부하기 (3) - Array List : https://
kor45cw.tistory.com/3
[3] Swift의 Array 완전 정복 – 01. 생성과 조작 : https://
soooprmx.com/archives/7045
[4] (Swift 기초) 자료구조(Collection) - 배열(Array) (2) : https://
m.blog.naver.com/PostView.nhn?
blogId=el_vin&logNo=221019918085&categoryNo=10&proxy
Referer=&proxyReferer=https:%2F%2Fwww.google.com%2F
[5] [Swift4] 컬렉션 타입 ::: Array / Dictionary / 메소드 /
Optional / nil : https://yereol.tistory.com/9
References
[6] Swift Language 배열 : https://sodocumentation.net/ko/
swift/topic/284/배열
[7] Swift Collection Types : https://
www.hohyeonmoon.com/blog/swift-collection-types/
[8] 10장 Swift 기초 8, 묶음(collection) 자료 구조, 배열(array) :
https://www.youtube.com/watch?v=UgMHDoFpN9M
[9] Swift의 Sequence와 Collection에 대해 알아야 하는것들 :
https://academy.realm.io/kr/posts/try-swift-soroush-
khanlou-sequence-collection/
[10] 자료구조: Linked List 대 ArrayList : http://
www.nextree.co.kr/p6506/
Thank you!

More Related Content

What's hot

제4장 sql 함수를 사용해보기
제4장 sql 함수를 사용해보기제4장 sql 함수를 사용해보기
제4장 sql 함수를 사용해보기
sang doc Lee
 
Python 강좌 발표 자료
Python 강좌 발표 자료Python 강좌 발표 자료
Python 강좌 발표 자료
Soobin Jung
 
3.자료구조
3.자료구조3.자료구조
3.자료구조
명준 김
 
20111025 Excel의 VBA, 매크로. 그리고 파이썬으로 함께하는 반복작업
20111025 Excel의 VBA, 매크로. 그리고 파이썬으로 함께하는 반복작업20111025 Excel의 VBA, 매크로. 그리고 파이썬으로 함께하는 반복작업
20111025 Excel의 VBA, 매크로. 그리고 파이썬으로 함께하는 반복작업
Jiho Lee
 
[Algorithm] Radix Sort
[Algorithm] Radix Sort[Algorithm] Radix Sort
[Algorithm] Radix Sort
Bill Kim
 
파이썬 엑셀_csv 처리하기
파이썬 엑셀_csv 처리하기파이썬 엑셀_csv 처리하기
파이썬 엑셀_csv 처리하기
Yong Joon Moon
 
Data Structures
Data StructuresData Structures
Data Structures
skku_npc
 
연결 리스트(기초)
연결 리스트(기초)연결 리스트(기초)
연결 리스트(기초)
Lee Geonhee
 
[Swift] Tuple
[Swift] Tuple[Swift] Tuple
[Swift] Tuple
Bill Kim
 
Binary Search
Binary SearchBinary Search
Binary Search
skku_npc
 
Python + Excel
Python + Excel Python + Excel
Python + Excel
POSTECH
 
[Algorithm] Insertion Sort
[Algorithm] Insertion Sort[Algorithm] Insertion Sort
[Algorithm] Insertion Sort
Bill Kim
 
Python 스터디
Python 스터디Python 스터디
Python 스터디
sanghyuck Na
 
05_STL컨테이너정리
05_STL컨테이너정리05_STL컨테이너정리
05_STL컨테이너정리noerror
 
자료구조6보고서
자료구조6보고서자료구조6보고서
자료구조6보고서KimChangHoen
 
[Algorithm] Quick Sort
[Algorithm] Quick Sort[Algorithm] Quick Sort
[Algorithm] Quick Sort
Bill Kim
 
Project#6 오탈자 검사 D0 Hwp
Project#6 오탈자 검사 D0 HwpProject#6 오탈자 검사 D0 Hwp
Project#6 오탈자 검사 D0 HwpKimjeongmoo
 
amugona study 3rd
amugona study 3rdamugona study 3rd
amugona study 3rd
who7117
 
20 swift 집합형
20 swift 집합형20 swift 집합형
20 swift 집합형
Changwon National University
 

What's hot (20)

제4장 sql 함수를 사용해보기
제4장 sql 함수를 사용해보기제4장 sql 함수를 사용해보기
제4장 sql 함수를 사용해보기
 
Python 강좌 발표 자료
Python 강좌 발표 자료Python 강좌 발표 자료
Python 강좌 발표 자료
 
3.자료구조
3.자료구조3.자료구조
3.자료구조
 
20111025 Excel의 VBA, 매크로. 그리고 파이썬으로 함께하는 반복작업
20111025 Excel의 VBA, 매크로. 그리고 파이썬으로 함께하는 반복작업20111025 Excel의 VBA, 매크로. 그리고 파이썬으로 함께하는 반복작업
20111025 Excel의 VBA, 매크로. 그리고 파이썬으로 함께하는 반복작업
 
Apply교육
Apply교육Apply교육
Apply교육
 
[Algorithm] Radix Sort
[Algorithm] Radix Sort[Algorithm] Radix Sort
[Algorithm] Radix Sort
 
파이썬 엑셀_csv 처리하기
파이썬 엑셀_csv 처리하기파이썬 엑셀_csv 처리하기
파이썬 엑셀_csv 처리하기
 
Data Structures
Data StructuresData Structures
Data Structures
 
연결 리스트(기초)
연결 리스트(기초)연결 리스트(기초)
연결 리스트(기초)
 
[Swift] Tuple
[Swift] Tuple[Swift] Tuple
[Swift] Tuple
 
Binary Search
Binary SearchBinary Search
Binary Search
 
Python + Excel
Python + Excel Python + Excel
Python + Excel
 
[Algorithm] Insertion Sort
[Algorithm] Insertion Sort[Algorithm] Insertion Sort
[Algorithm] Insertion Sort
 
Python 스터디
Python 스터디Python 스터디
Python 스터디
 
05_STL컨테이너정리
05_STL컨테이너정리05_STL컨테이너정리
05_STL컨테이너정리
 
자료구조6보고서
자료구조6보고서자료구조6보고서
자료구조6보고서
 
[Algorithm] Quick Sort
[Algorithm] Quick Sort[Algorithm] Quick Sort
[Algorithm] Quick Sort
 
Project#6 오탈자 검사 D0 Hwp
Project#6 오탈자 검사 D0 HwpProject#6 오탈자 검사 D0 Hwp
Project#6 오탈자 검사 D0 Hwp
 
amugona study 3rd
amugona study 3rdamugona study 3rd
amugona study 3rd
 
20 swift 집합형
20 swift 집합형20 swift 집합형
20 swift 집합형
 

Similar to [Swift] Data Structure - Array

[Swift] Data Structure - Queue
[Swift] Data Structure - Queue[Swift] Data Structure - Queue
[Swift] Data Structure - Queue
Bill Kim
 
자바로 배우는 자료구조
자바로 배우는 자료구조자바로 배우는 자료구조
자바로 배우는 자료구조
중선 곽
 
개경프 1주차 Stl study
개경프 1주차 Stl study개경프 1주차 Stl study
개경프 1주차 Stl study
경 송
 
02. data structure and stl
02. data structure and stl02. data structure and stl
02. data structure and stl
승혁 조
 
Collection framework
Collection frameworkCollection framework
Collection framework
ssuser34b989
 
STL study (skyLab)
STL study (skyLab)STL study (skyLab)
STL study (skyLab)
Gyeongwook Choi
 
Data structure review (summer study)
Data structure review (summer study)Data structure review (summer study)
Data structure review (summer study)
Melon Lemon
 
Java_08 collection
Java_08 collectionJava_08 collection
Java_08 collection
Hong Hyo Sang
 
Java collection
Java collectionJava collection
Java collection
Hyosang Hong
 
[NEXT] Android 개발 경험 프로젝트 2일차 (Intent, ListView, Adapter)
[NEXT] Android 개발 경험 프로젝트 2일차 (Intent, ListView, Adapter)[NEXT] Android 개발 경험 프로젝트 2일차 (Intent, ListView, Adapter)
[NEXT] Android 개발 경험 프로젝트 2일차 (Intent, ListView, Adapter)
YoungSu Son
 
[Swift] Subscripts
[Swift] Subscripts[Swift] Subscripts
[Swift] Subscripts
Bill Kim
 
Java stream v0.1
Java stream v0.1Java stream v0.1
Java stream v0.1
Hyosang Hong
 
Java stream v0.1
Java stream v0.1Java stream v0.1
Java stream v0.1
Hyosang Hong
 
데이터 분석 5 - Java Collection Framework - LinkedList 파헤치기
데이터 분석 5 - Java Collection Framework - LinkedList 파헤치기데이터 분석 5 - Java Collection Framework - LinkedList 파헤치기
데이터 분석 5 - Java Collection Framework - LinkedList 파헤치기
Jaewook Byun
 
[SOPT] 데이터 구조 및 알고리즘 스터디 - #03 : 정렬 (기본, 효율, 초효율
[SOPT] 데이터 구조 및 알고리즘 스터디 - #03 : 정렬 (기본, 효율, 초효율[SOPT] 데이터 구조 및 알고리즘 스터디 - #03 : 정렬 (기본, 효율, 초효율
[SOPT] 데이터 구조 및 알고리즘 스터디 - #03 : 정렬 (기본, 효율, 초효율
S.O.P.T - Shout Our Passion Together
 
2014.07.26 KSUG와 지앤선이 함께하는 테크니컬 세미나 - 나의 첫번째 자바8 람다식 (정대원)
2014.07.26 KSUG와 지앤선이 함께하는 테크니컬 세미나 - 나의 첫번째 자바8 람다식 (정대원)2014.07.26 KSUG와 지앤선이 함께하는 테크니컬 세미나 - 나의 첫번째 자바8 람다식 (정대원)
2014.07.26 KSUG와 지앤선이 함께하는 테크니컬 세미나 - 나의 첫번째 자바8 람다식 (정대원)
JiandSon
 
[Swift] Collection types
[Swift] Collection types[Swift] Collection types
[Swift] Collection types
Bill Kim
 
나에 첫번째 자바8 람다식 지앤선
나에 첫번째 자바8 람다식   지앤선나에 첫번째 자바8 람다식   지앤선
나에 첫번째 자바8 람다식 지앤선daewon jeong
 
Java(4/4)
Java(4/4)Java(4/4)
Java(4/4)
handfoot
 

Similar to [Swift] Data Structure - Array (20)

[Swift] Data Structure - Queue
[Swift] Data Structure - Queue[Swift] Data Structure - Queue
[Swift] Data Structure - Queue
 
자바로 배우는 자료구조
자바로 배우는 자료구조자바로 배우는 자료구조
자바로 배우는 자료구조
 
개경프 1주차 Stl study
개경프 1주차 Stl study개경프 1주차 Stl study
개경프 1주차 Stl study
 
02. data structure and stl
02. data structure and stl02. data structure and stl
02. data structure and stl
 
Collection framework
Collection frameworkCollection framework
Collection framework
 
STL study (skyLab)
STL study (skyLab)STL study (skyLab)
STL study (skyLab)
 
Data structure review (summer study)
Data structure review (summer study)Data structure review (summer study)
Data structure review (summer study)
 
Java_08 collection
Java_08 collectionJava_08 collection
Java_08 collection
 
Java collection
Java collectionJava collection
Java collection
 
[NEXT] Android 개발 경험 프로젝트 2일차 (Intent, ListView, Adapter)
[NEXT] Android 개발 경험 프로젝트 2일차 (Intent, ListView, Adapter)[NEXT] Android 개발 경험 프로젝트 2일차 (Intent, ListView, Adapter)
[NEXT] Android 개발 경험 프로젝트 2일차 (Intent, ListView, Adapter)
 
[Swift] Subscripts
[Swift] Subscripts[Swift] Subscripts
[Swift] Subscripts
 
Java stream v0.1
Java stream v0.1Java stream v0.1
Java stream v0.1
 
Java stream v0.1
Java stream v0.1Java stream v0.1
Java stream v0.1
 
Scala
ScalaScala
Scala
 
데이터 분석 5 - Java Collection Framework - LinkedList 파헤치기
데이터 분석 5 - Java Collection Framework - LinkedList 파헤치기데이터 분석 5 - Java Collection Framework - LinkedList 파헤치기
데이터 분석 5 - Java Collection Framework - LinkedList 파헤치기
 
[SOPT] 데이터 구조 및 알고리즘 스터디 - #03 : 정렬 (기본, 효율, 초효율
[SOPT] 데이터 구조 및 알고리즘 스터디 - #03 : 정렬 (기본, 효율, 초효율[SOPT] 데이터 구조 및 알고리즘 스터디 - #03 : 정렬 (기본, 효율, 초효율
[SOPT] 데이터 구조 및 알고리즘 스터디 - #03 : 정렬 (기본, 효율, 초효율
 
2014.07.26 KSUG와 지앤선이 함께하는 테크니컬 세미나 - 나의 첫번째 자바8 람다식 (정대원)
2014.07.26 KSUG와 지앤선이 함께하는 테크니컬 세미나 - 나의 첫번째 자바8 람다식 (정대원)2014.07.26 KSUG와 지앤선이 함께하는 테크니컬 세미나 - 나의 첫번째 자바8 람다식 (정대원)
2014.07.26 KSUG와 지앤선이 함께하는 테크니컬 세미나 - 나의 첫번째 자바8 람다식 (정대원)
 
[Swift] Collection types
[Swift] Collection types[Swift] Collection types
[Swift] Collection types
 
나에 첫번째 자바8 람다식 지앤선
나에 첫번째 자바8 람다식   지앤선나에 첫번째 자바8 람다식   지앤선
나에 첫번째 자바8 람다식 지앤선
 
Java(4/4)
Java(4/4)Java(4/4)
Java(4/4)
 

More from Bill Kim

[Algorithm] Sorting Comparison
[Algorithm] Sorting Comparison[Algorithm] Sorting Comparison
[Algorithm] Sorting Comparison
Bill Kim
 
[Algorithm] Big O Notation
[Algorithm] Big O Notation[Algorithm] Big O Notation
[Algorithm] Big O Notation
Bill Kim
 
[Algorithm] Shell Sort
[Algorithm] Shell Sort[Algorithm] Shell Sort
[Algorithm] Shell Sort
Bill Kim
 
[Algorithm] Heap Sort
[Algorithm] Heap Sort[Algorithm] Heap Sort
[Algorithm] Heap Sort
Bill Kim
 
[Algorithm] Merge Sort
[Algorithm] Merge Sort[Algorithm] Merge Sort
[Algorithm] Merge Sort
Bill Kim
 
[Algorithm] Bubble Sort
[Algorithm] Bubble Sort[Algorithm] Bubble Sort
[Algorithm] Bubble Sort
Bill Kim
 
[Algorithm] Recursive(재귀)
[Algorithm] Recursive(재귀)[Algorithm] Recursive(재귀)
[Algorithm] Recursive(재귀)
Bill Kim
 
[Swift] Data Structure - AVL
[Swift] Data Structure - AVL[Swift] Data Structure - AVL
[Swift] Data Structure - AVL
Bill Kim
 
[Swift] Data Structure - Binary Search Tree
[Swift] Data Structure - Binary Search Tree[Swift] Data Structure - Binary Search Tree
[Swift] Data Structure - Binary Search Tree
Bill Kim
 
[Swift] Data Structure - Graph(BFS)
[Swift] Data Structure - Graph(BFS)[Swift] Data Structure - Graph(BFS)
[Swift] Data Structure - Graph(BFS)
Bill Kim
 
[Swift] Data Structure - Graph(DFS)
[Swift] Data Structure - Graph(DFS)[Swift] Data Structure - Graph(DFS)
[Swift] Data Structure - Graph(DFS)
Bill Kim
 
[Swift] Data Structure - Binary Tree
[Swift] Data Structure - Binary Tree[Swift] Data Structure - Binary Tree
[Swift] Data Structure - Binary Tree
Bill Kim
 
[Swift] Data Structure - Tree
[Swift] Data Structure - Tree[Swift] Data Structure - Tree
[Swift] Data Structure - Tree
Bill Kim
 
[Swift] Data Structure - Graph
[Swift] Data Structure - Graph[Swift] Data Structure - Graph
[Swift] Data Structure - Graph
Bill Kim
 
[Swift] Data Structure - Dequeue
[Swift] Data Structure - Dequeue[Swift] Data Structure - Dequeue
[Swift] Data Structure - Dequeue
Bill Kim
 
[Swift] Data Structure Introduction
[Swift] Data Structure Introduction[Swift] Data Structure Introduction
[Swift] Data Structure Introduction
Bill Kim
 
Design Pattern Introduction
Design Pattern IntroductionDesign Pattern Introduction
Design Pattern Introduction
Bill Kim
 
[Swift] Visitor
[Swift] Visitor[Swift] Visitor
[Swift] Visitor
Bill Kim
 
[Swift] Template Method
[Swift] Template Method[Swift] Template Method
[Swift] Template Method
Bill Kim
 
[Swift] State
[Swift] State[Swift] State
[Swift] State
Bill Kim
 

More from Bill Kim (20)

[Algorithm] Sorting Comparison
[Algorithm] Sorting Comparison[Algorithm] Sorting Comparison
[Algorithm] Sorting Comparison
 
[Algorithm] Big O Notation
[Algorithm] Big O Notation[Algorithm] Big O Notation
[Algorithm] Big O Notation
 
[Algorithm] Shell Sort
[Algorithm] Shell Sort[Algorithm] Shell Sort
[Algorithm] Shell Sort
 
[Algorithm] Heap Sort
[Algorithm] Heap Sort[Algorithm] Heap Sort
[Algorithm] Heap Sort
 
[Algorithm] Merge Sort
[Algorithm] Merge Sort[Algorithm] Merge Sort
[Algorithm] Merge Sort
 
[Algorithm] Bubble Sort
[Algorithm] Bubble Sort[Algorithm] Bubble Sort
[Algorithm] Bubble Sort
 
[Algorithm] Recursive(재귀)
[Algorithm] Recursive(재귀)[Algorithm] Recursive(재귀)
[Algorithm] Recursive(재귀)
 
[Swift] Data Structure - AVL
[Swift] Data Structure - AVL[Swift] Data Structure - AVL
[Swift] Data Structure - AVL
 
[Swift] Data Structure - Binary Search Tree
[Swift] Data Structure - Binary Search Tree[Swift] Data Structure - Binary Search Tree
[Swift] Data Structure - Binary Search Tree
 
[Swift] Data Structure - Graph(BFS)
[Swift] Data Structure - Graph(BFS)[Swift] Data Structure - Graph(BFS)
[Swift] Data Structure - Graph(BFS)
 
[Swift] Data Structure - Graph(DFS)
[Swift] Data Structure - Graph(DFS)[Swift] Data Structure - Graph(DFS)
[Swift] Data Structure - Graph(DFS)
 
[Swift] Data Structure - Binary Tree
[Swift] Data Structure - Binary Tree[Swift] Data Structure - Binary Tree
[Swift] Data Structure - Binary Tree
 
[Swift] Data Structure - Tree
[Swift] Data Structure - Tree[Swift] Data Structure - Tree
[Swift] Data Structure - Tree
 
[Swift] Data Structure - Graph
[Swift] Data Structure - Graph[Swift] Data Structure - Graph
[Swift] Data Structure - Graph
 
[Swift] Data Structure - Dequeue
[Swift] Data Structure - Dequeue[Swift] Data Structure - Dequeue
[Swift] Data Structure - Dequeue
 
[Swift] Data Structure Introduction
[Swift] Data Structure Introduction[Swift] Data Structure Introduction
[Swift] Data Structure Introduction
 
Design Pattern Introduction
Design Pattern IntroductionDesign Pattern Introduction
Design Pattern Introduction
 
[Swift] Visitor
[Swift] Visitor[Swift] Visitor
[Swift] Visitor
 
[Swift] Template Method
[Swift] Template Method[Swift] Template Method
[Swift] Template Method
 
[Swift] State
[Swift] State[Swift] State
[Swift] State
 

[Swift] Data Structure - Array

  • 1. SWIFT Data Structure - Array Bill Kim(김정훈) | ibillkim@gmail.com
  • 3. Array List 자료구조에서 가장 기본이 되는 구조는 배열(리스트)입니다. 리스트는 크게 아래와 같이 2개의 리스트로 구분할 수 있습니다. 순차 리스트 : 배열을 기반으로 구현된 리스트 연결 리스트 : 메모리의 동적 할당을 기반으로 구현된 리스트 본 강의에서는 Swift 코드를 활용하여 순차 리스트에 대해서 살펴 봅니다.
  • 4. Concept 순차리스트는 아래와 같이 특정 자료를 정해진 공간안에서 순차적 으로 저장 및 가져오는 자료구조입니다.
  • 5. Features 순차 리스트(Array)의 특징을 살펴보면 아래와 같습니다. - 데이터를 순차적으로 저장합니다. - 데이터 중복 저장을 허용합니다. - 배열의 총 길이는 초기에 결정되어야 합니다.(변경 불가) - 인덱스 값을 기준으로 데이터의 참조가 가능합니다. - 삭제의 과정에서 데이터의 이동이 빈번하게 일어납니다.
  • 6. Implementation Swift를 활용하여 Array 를 구현해보겠습니다. 우선 필요한 메소드는 아래와 같습니다. - init() : 배열의 크기를 설정하는 초기화 함수 - insert() : 데이터 입력 - remove() : 특정 인덱스의 데이터 삭제 - removeAll() : 모든 데이터 삭제 - get() : 특정 인덱스의 데이터 값을 반환 - count() : 현재 배열의 크기를 반환
  • 7. Implementation 가장 데이터의 기본이 되는 Node 클래스 입니다. 해당 Node 클래스는 모든 데이터 형식을 받을 수 있도록 Generic 형태로 구현이 되어 있습니다. class Node<T> { fileprivate var data:T init(_ data: T) { self.data = data } }
  • 8. Implementation class ArrayList<T> { private var size:Int private var list:[Node<T>] init(size:Int) { self.list = [Node<T>]() self.size = size } func insert(item:T) { if self.list.count < size { self.list.append(Node<T>(item)) } } func remove(at:Int) { if self.list.count <= 0 { return } if self.list.count <= at { return } self.list.remove(at: at) } func removeAll() { self.list.removeAll() } func get(index:Int) -> T { return self.list[index].data } func count() -> Int { size = list.count return size } }
  • 9. Implementation 아래와 같이 사용이 가능합니다. let list:ArrayList<Int> = ArrayList(size: 5) list.insert(item: 1) list.insert(item: 2) list.insert(item: 3) list.insert(item: 4) list.insert(item: 5) // 최대 리스트 크기가 5로 설정하였으므로 추가 불가 list.insert(item: 6) // 현재 리스트 카운트 : 5 print(list.count()) for i in 0..<list.count() { print(list.get(index: i)) // 1 // 2 // 3 // 4 // 5 }
  • 10. Implementation // 4번째 요소 삭제 list.remove(at: 3) // 현재 리스트 카운트 : 4 print(list.count()) for i in 0..<list.count() { print(list.get(index: i)) // 1 // 2 // 3 // 5 } list.removeAll() // 현재 리스트 카운트 : 0 print(list.count())
  • 11. References [1] [Swift 자료구조 ch01] 자료구조 살펴보기 : https:// kor45cw.tistory.com/238 [2] Swift로 자료구조, 알고리즘 공부하기 (3) - Array List : https:// kor45cw.tistory.com/3 [3] Swift의 Array 완전 정복 – 01. 생성과 조작 : https:// soooprmx.com/archives/7045 [4] (Swift 기초) 자료구조(Collection) - 배열(Array) (2) : https:// m.blog.naver.com/PostView.nhn? blogId=el_vin&logNo=221019918085&categoryNo=10&proxy Referer=&proxyReferer=https:%2F%2Fwww.google.com%2F [5] [Swift4] 컬렉션 타입 ::: Array / Dictionary / 메소드 / Optional / nil : https://yereol.tistory.com/9
  • 12. References [6] Swift Language 배열 : https://sodocumentation.net/ko/ swift/topic/284/배열 [7] Swift Collection Types : https:// www.hohyeonmoon.com/blog/swift-collection-types/ [8] 10장 Swift 기초 8, 묶음(collection) 자료 구조, 배열(array) : https://www.youtube.com/watch?v=UgMHDoFpN9M [9] Swift의 Sequence와 Collection에 대해 알아야 하는것들 : https://academy.realm.io/kr/posts/try-swift-soroush- khanlou-sequence-collection/ [10] 자료구조: Linked List 대 ArrayList : http:// www.nextree.co.kr/p6506/