From 33b7f34cafed10339885e7edb55cb665542cd04c Mon Sep 17 00:00:00 2001 From: Zameelnm96 <47120059+Zameelnm96@users.noreply.github.com> Date: Wed, 6 Feb 2019 12:42:44 +0530 Subject: [PATCH] without_n1_variable.java We dont want to create a n1 variable here. it will be automatically eligible for garbage collection --- DataStructuresJava/src/LinkedList.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/DataStructuresJava/src/LinkedList.java b/DataStructuresJava/src/LinkedList.java index 1c569a7..31d6e26 100644 --- a/DataStructuresJava/src/LinkedList.java +++ b/DataStructuresJava/src/LinkedList.java @@ -68,10 +68,10 @@ public void deleteAt(int index) { n = n.next; } - n1 = n.next; - n.next = n1.next; + + n.next = (n.next).next;//we dont want n1 this will automatically eligible for garbage collection //System.out.println("n1 " + n1.data); - n1 = null; + } }