logo

// here Node has 3 fields (element, next and previous).

   

Added on  2019-09-30

2 Pages290 Words178 Views
// here Node has 3 fields (element, next and previous)public class CircularlyDoublyLinkedList<E> {private node<E> tail = null;private int size = 0;public CircularlyDoublyLinkedList(){ }public int size(){return size;}public boolean isEmpty(){return size == 0;}public E first(){if (isEmpty()) return null;return tail.getNext().getElement();}public E last(){if(isEmpty()) return null;return tail.getElement();}public void rotate(){if(tail != NULL){tail = tail.getNext();}}public void addFirst(E e){if(size==0){tail = new Node<> (e, null);tail.setNext(tail);tail.setPrevious(tail);} else {Node<E> newest = new Node<> (e, tail.getNext(), tail);tail.setNext(newest);newest.getNext().setPrevious(newest);}size++;}public void addLast(E e){addFirst(e);tail = tail.getNext();}public E removeFirst(){if (isEmpty()) return null;Node<E> head = tail.getNext();

End of preview

Want to access all the pages? Upload your documents or become a member.

Related Documents
Implementation of Binary Search Tree in Java
|13
|706
|64

Vehicle Data Inventory System
|18
|2151
|53

CS4343 Programming Assignment
|19
|2084
|97

C++ programming questions on recursion, loops, classes, and data structures
|6
|1265
|171

Quick Short Assignment 2022
|16
|1651
|15

Quick Sort Assignment 2022
|16
|1682
|22