From 8e707b823ac1ea91a8c17846ad5fca6a1e2b5a6a Mon Sep 17 00:00:00 2001 From: Jigyasa Khaneja Date: Tue, 9 Oct 2018 23:04:51 +0530 Subject: [PATCH] Linked List Implementation (#312) --- LL.java | 129 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 129 insertions(+) create mode 100644 LL.java diff --git a/LL.java b/LL.java new file mode 100644 index 00000000..1cafcc30 --- /dev/null +++ b/LL.java @@ -0,0 +1,129 @@ +class Node +{ + private int data; + public Node next; + + + public Node(int data) + { + this.data=data; + this.next=null; + } + public int getData() + { + return this.data; + } +} + +class LinkedList +{ + private Node head; + private Node tail; + public int size; + + public LinkedList() + { + head=null; + tail=null; + size=0; + } + + public boolean isEmpty() + { + return head==tail; + } + + public int getSize() + { + return size; + } + + public void insertAtStart(int val) + { + Node newNode = new Node(val); + size++ ; + if(head == null) + { + head = newNode; + tail = head; + } + else + { + newNode.next=head; + head=newNode; + } + } + + public void insertAtLast(int val) + { + Node newNode=new Node(val); + size++; + if(head==null) + { + head=newNode; + tail=newNode; + } + else + { + tail.next=newNode; + tail=newNode; + } + } + public void insertAtPos(int val, int pos) + { + Node newNode= new Node(val); + Node temp=head; + pos=pos-1; + for(int i=0;i