Showing posts with label LinkedList. Show all posts
Showing posts with label LinkedList. Show all posts

Thursday, August 16, 2018

LinkedList custom implementation in Java

Objectives


Today i'm going to introduce you in my custom LinkedList implementation.Below is prepared diagram which shows internal class's structure. Every Node handles reference to next Node. The last Node has an empty reference. There are two fields which hold reference to first and last Nodes.




Below is internal Node's structure which holds items and references.


private class Node<T extends Object>{
        Node<T> next;
        T object;
     
        public Node(T object){
            this.next = null;
            this.object = object;
        }
     
        public Node(T object, Node<T> next){
            next.setNext(this);
            this.next = null;
            this.object = object;
        }

        public Node<T> getNext() {
            return next;
        }

        public void setNext(Node<T> next) {
            this.next = next;
        }

        public T getObject() {
            return object;
        }

        public void setObject(T object) {
            this.object = object;
        }     
     
    }