본문 바로가기

Programing/Java

[Java] 이중연결리스트와 ListIterator 인터페이스

728x90
반응형

[Java] 이중연결리스트와 ListIterator 인터페이스


이중 연결 리스트

  • 각각의 노드가 다음 노드와 이전 노드의 주소를 가지는 연결 리스트
  • 양방향의 순회가 가능

Node Class

private static class Node<E> {
	
    private E data;
    private Node<E> next = null;
    private Node<E> prev = null;
    
    private Node(E dataItem){
    	data = dataItem;
    }
    
}

 

ListIterator<E> 인터페이스

  • ListIterator는 Iterator를 확장한다.
  • Iterator처럼 개념적으로는 노드와 노드 사이를 가리킨다.
  • ListIterator의 위치는 0에서 size까지의 index로 표현한다.
Method Behavior
void add(E obj) Inserts object obj into the list just before the item that would be returned by next call to method next and after the item that would have been returned by method previous. If method previous is called after add, the newly inserted object will be returned.
boolean hasNext() Returns true if next will not throw an exception.
boolean hasPrevious() Returns ture if previous will not throw an exception.
E next() Returns the next object and moves the iterator forward. If the iterator is at the end, the NoSuchElementException is thrown.
int nextIndex() Returns the index of the item that will be returned by the next call to next. If the iterator is at the end, the list size is returned.
E previous() Returns the previous object and moves the iterator backward. If the iterator is at the beginning of the list, the NoSuchElementException is thrown.
int previousIndex() Returns the index of the item that will be returned by the next call to previous. It the iterator is at the beginning of the list, -1 is returned.
void remove() Removes the last item returned from a call to next or previous. If a call to remove is not preceded by a call to next or previous, the IllegalStateException is thrown.
void set(E obj) Replaces the last item returned form a call to next or previous with obj. If a call to set is not preceded by a call to next or previous, the IllegalStateException is thrown
728x90
반응형

'Programing > Java' 카테고리의 다른 글

[Java] String,StringBuffer,StringBuilder 메서드 정리  (0) 2022.07.20
[Java] Iterator  (0) 2021.01.13
[Java] 리스트  (0) 2021.01.10
[Java] List 관련 메서드  (0) 2021.01.04
[Java] Generic Programming  (0) 2021.01.04