You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
privateEelement; // reference to the element stored at this nodeprivateNode<E> next; // reference to the subsequent node in the list
CLL class variables:
privateNode<E> tail = null; // we store tail (but not head)privateintsize = 0; // number of nodes in the list
methods:
size( ): Returns the number of elements in the list.
isEmpty( ): Returns true if the list is empty, and false otherwise.
first( ): Returns (but does not remove) the first element in the list.
last( ): Returns (but does not remove) the last element in the list.
addFirst(e): Adds a new element to the front of the list.
addLast(e): Adds a new element to the end of the list.
removeFirst( ): Removes and returns the first element of the list.
rotate( ): Moves the first element to the end of the list.
Operations
Access
Search
Insertion
Deletion
Best case time complexity
O(1)
O(1)
O(1)
O(1)
Worst Case time complexity
O(n)
O(n)
O(n)
O(n)
Average time complexity
O(n)
O(n)
O(1)
O(1)
special method:
publicvoidrotate( ) { // rotate the first element to the back of the listif (tail != null) // if empty, do nothingtail = tail.getNext( ); // the old head becomes the new tail
}