티스토리 뷰
해커랭크 Day 15 챌린지를 시작해보자. 🔥
오늘은 LinkedList에 대해서 배웠다.
먼저 소스코드부터 확인하자.
import java.util.LinkedList;
public class LinkedListUS {
// Properties
Node head;
int count;
// Constructors
public LinkedListUS() {
head = null;
count = 0;
}
public LinkedListUS(Node newHead) {
head = newHead;
count = 1;
}
// Methods
// add
public void add(int newData) {
Node temp = new Node(newData);
Node current = head;
while(current.getNext() != null) {
current = current.getNext();
}
current.setNext(temp);
count++;
}
// get
public int get(int index) {
if (index <= 0) {
return -1;
}
Node current = head;
for(int i=0; i<index; i++) {
current = current.getNext();
}
return current.getData();
}
// size
public int size() {
return count;
}
// isEmpty
public boolean isEmpty() {
return head == null;
}
// remove
public void remove() {
// remove from the back of the list
Node current = head;
while(current.getNext().getNext() != null) {
current = current.getNext();
}
current.setNext(null);
count--;
}
public static void main(String[] args) {
LinkedList<String> linkedList = new LinkedList<String>();
linkedList.add("Alice");
System.out.println(linkedList);
linkedList.add("Alicey");
}
}
linkedList는 학교 자료구조 시간에 처음 배웠고
자바의 정석 강의를 통해
조금 더 자세히 알게 되었다.
위 소스 코드는 LinkedList가 무엇인지 알고 있어야
이해할 수 있으므로
만약 LinkedList가 무엇인지 모른다면
다음의 사이트를 참고하자.
[자바의정석] ch 11-12 LinkedList - 배열의 장단점
🤔 LinkedList 배열의 장단점 ✅ 장점 ✔ 배열은 구조가 간단하고 데이터를 읽는 데 걸리는 시간(접근시간, access time)이 짧다. ✅ 단점 ✔ 크기를 변경할 수 없다. 크기를 변경해야 할 경우 새로운
dandev.tistory.com
[자바의 정석] Ch11-1 컬레션 프레임웍(collections framework) / Ch 11-7 ArrayList
🤔 컬렉션 프레임워크(collections framework) ✔ 컬렉션(collection) - 여러 객체(데이터)를 모아 놓은 것 ✔ 프레임웍(framework) - 표준화, 정형화된 체계적인 프로그래밍 방식 ✔ 컬렉션 프레임웍(collections
dandev.tistory.com
위 두 사이트는 필자가 위에서 말한
자바의 정석 강의 내용을
정리해둔 포스팅으로 LinkedList의 개념이 나오니
함께 살펴보면 도움될 것이다!
그 외에 소스코드에 대한 설명은
linkedList에 대한 이해를 바탕으로 진행하기 때문에
딱히 설명하지 않겠다!!
만약 이해가 되지 않는 부분이 있다면 댓글을 통해 질문하길 바란다!
그럼 필자는 Day 15 문제 풀이 포스팅으로 다시 찾아오겠다!
'해커랭크 챌린지' 카테고리의 다른 글
[hackerrank] hackerrank challenges Day 16 자바 강의 리뷰 (0) | 2022.07.09 |
---|---|
[hackerrank] hackerrank challenges Day 15 자바 코드 리뷰 (0) | 2022.07.08 |
[hackerrank] hackerrank challenges Day 14 자바 코드 리뷰 (0) | 2022.07.07 |
[hackerrank] hackerrank challenges Day 14 자바 강의 리뷰 (0) | 2022.07.07 |
[hackerrank] hackerrank challenges Day 13 자바 코드 리뷰 (0) | 2022.07.06 |
- Total
- Today
- Yesterday
- BAEKJOON
- 백준
- 정보처리산업기사 공부법
- 디버깅
- 22 정보처리 산업기사
- ORM
- 이코테
- 해커랭크 자바
- 정보처리 산업기사
- 해커랭크 챌린지
- 해커랭크 자바 챌린지
- hackerrank
- 강의
- queue
- 자바
- stack
- 자바의 정석
- 나동빈
- Java
- hackerrank challenges
- JPA
- 소스코드
- 해커랭크
- 챌린지
- 코드
- challenges
- 22 정보처리산업기사
- 그리디
- LinkedList
- 정보처리산업기사
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |