



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
An introduction to doubly linked lists, a type of linked list data structure where each node contains references to both the previous and next nodes. creating and displaying a simple linked list, inserting a node, and deleting a node. It also includes the implementation of a DoublyLinkedList class in Java.
What you will learn
Typology: Study notes
1 / 5
This page cannot be seen from the preview
Don't miss anything!
1 class Node
1 Node
1 Node
1 Node
1 Node
1 current.previous.next = current.next; 2 current.next.previous = current.previous;
(^2) * To change this template, choose Tools | Templates (^3) * and open the template in the editor. (^4) */ 5 package doublylinkedlist; 6 7 import java.util.Iterator; 8 import java.util.ListIterator;
79 @Override 80 public E next() { 81 if (!hasNext()){ 82 throw new NoSuchElementException(); 83 84 } 85 lastAccessed = current; 86 E item = current.data; 87 current = current.next; 88 index++; 89 return item; 90 } 91 92 @Override 93 public boolean hasPrevious() { 94 return index > 0; 95 } 96 97 @Override 98 public E previous() { 99 if (!hasPrevious()){ 100 throw new NoSuchElementException(); 101 } 102 current = current.previous; 103 lastAccessed = current; 104 index--; 105 return current.data; 106 } 107 108 @Override 109 public int nextIndex() { 110 return index; 111 } 112 113 @Override 114 public int previousIndex() { 115 return index - 1; 116 } 117 118 @Override 119 public void remove() { 120 Node a = lastAccessed.previous; 121 Node b = lastAccessed.next; 122 a.next = b; 123 b.previous = a; 124 N--; 125 index--; 126 lastAccessed = null ; 127 } 128 129 @Override 130 public void set(E e) { 131 throw new UnsupportedOperationException("Not supported yet."); 132 } 133 134 @Override 135 public void add(E e) { 136 Node b = new Node(e); 137 Node a = current.previous; 138 Node c = current; 139 a.next = b; 140 b.next = c; 141 c.previous = b; 142 b.previous = a; 143 index++; 144 N++;
145 lastAccessed = null ; 146 } 147 148 } 149 150 /** (^151) * @param args the command line arguments (^152) */ 153 public static void main(String[] args) { 154 DoublyLinkedList