리스트 List

이슬비·2022년 11월 29일
0
post-thumbnail

자료구조와 알고리즘 A+ 기원.

1. List

: 이름, 멤버 등이 모인 형태 = set

2. ADT List

  • add: 요소 x 추가
  • add: 위치 i에 요소 x 추가
  • remove: x 삭제
  • remove: i번째 요소 삭제
  • get: i번째 요소 (요소 x) 가져오기
  • indexOf: i번째 요소 요소가져오기
  • clear: list의 모든 요소 삭제
  • size: 현재 list 속의 요소 개수 가져오기

3. Array List

  • 디자인 이슈
    1. 데이터 필드 선언을 어떻게 해야하는가?
    1. array의 파라미터 T를 초기화 하는 방법
      - @SuppressWarnings("unchecked")를 통해 type checking 에러 무시
    2. 안전하지 않은 프로그래밍
      1. en캡슐 방법에 어긋남
    3. 몇 가지의 code가 중복됨

4. Linked List

: 삽입&삭제가 많을 때 유용하며 배열 구조가 아닌 연결 구조

  • resizable 👍
  • more memory 👎
public class Linked_List<T> implements List<T>{
	class Node<T> {
    	private T data; // 현재 노드의 값
        private Node<T> next; // 다음 노트를 가리킴
        Node(T dataPortion) { // 다음 노드가 없을 때
        	this(dataPortion, null);
        }
        Node(T dataPortion, Node<T> nextNode){
        	data = dataPortioin;
            next = nextNode;
        }
        T getData(){
        	return data;
        }
        Node<T> getNextNode(){
        	return next;
        }
        void setData(T newData){
        	data = newData;
        }
        void setNextNode(Node<T> nextNode{
        next = nextNode;
        }
    }
private Node<T> list; //첫 번째 노트 선언
private int numberOfEntries;
public Linked_List(){}
public boolean add(T newEntry){}
public boolean add(int givenPosition, T newEntry){} // 내가 넣고 싶은 위치에 넣음
public boolean remove(T anEntry){}
public T remove(int givenPosition){}
public T get(int givenPositioin){}
public int indexOf(T anEntry){}
public void clear(){}
public int size(){}
public String toString(){}

Time Complexity

5. Variations

  • Sorted List
  • Singly Linked List
  • Doubly Linked List
  • Circular Linked List

1) Sorted List

  • add: 정렬된 상태로 삽입
  • remove: 요소 x 삭제
  • remove: i번째 요소 삭제
  • get: i번째 요소 가져오기
  • indexOf: i번째 요소가 무엇인지 가져오기
  • clear: list 내 모든 요소 삭제
  • size: 현재 list의 사이즈 반환

2) Singly Linked List

: next만 존재

3) Doubly Linked List

: prev, next 모두 존재

4) Circular Linked List

  • 마지막 노드의 다음 노드 = 첫 번째 노드
  • 첫 번째 노드의 이전 노드 = 마지막 노트
profile
정말 알아?

0개의 댓글