개발입문/JAVA
[30일코딩] LinkedList
haloaround
2017. 5. 7. 20:09
Day 15. LinkedList 에서는
Data Structure 에서 알고리즘을 직.접. 짜보는 시간을 가졌다.
어떻게 구현되는지 살짝 맛보기에 가까운 강의였는데~
그래도 뭔가 신기하고 신났다! (신난다신난다!)
컴공에서는 데이터 구조론이라는 과목으로 방대하게 배운다던데
주변 개발자들이 그거 학부때 공부하는 거 아니에요? 라고 일침하길래..
제대로 공부하는건 당분간은 미뤄두려고 한다.
본론 고고!!
Linked List
is a data structure
that consists of a group of nodes
which represent a sequence together
LinkedList 는 기차칸이 총 N 개인 기차이다.
각 기차칸 (노드) 는 이렇게 일련의 순서를 가지고 연결되어있다.
1번 기차칸은 2번 기차칸과 연결되어있고
2번 기차칸은 3번 기차칸과 연결되어있다 (...)
각 기차칸은 데이터와 그다음 기차칸을 가리키는 레퍼런스를 가지고 있다!
노드 Node
데이터 최소 단위 ( like atomic unit )
자료구조는 노드 간의 연관관계에 따라 다르게 구현된다.
Node 는 기본적으로 데이터와 다음 노드에 대한 레퍼런스를 가진다.
- head(시작노드), current(인덱스), temp(처리해야 되는 대상)
public static Node insert(Node head, int data) {
Node current;
Node temp = new Node(data);
if (head==null) {
head = temp;
} else {
current = head;
while(current.next!=null) {
current = current.next;
}
current.next = temp;
}
return head;
}
LinkedList 메소드는
API 보면서 익숙해져야지 :3
LinkedList
- add(E e), add(int index, E element)
- get(int index)
- set(int index, E element)
- indexOf(Object o)
- remove(int index), remove(Object o)
- clear()
http://docs.oracle.com/javase/8/docs/api/java/util/LinkedList.html