From caf2311583ed072d31f3ef7c3941d3b0d13b6db4 Mon Sep 17 00:00:00 2001 From: tejaspundpal <96496782+tejaspundpal@users.noreply.github.com> Date: Sun, 3 Sep 2023 07:24:48 +0530 Subject: [PATCH] Problem Solving --- .idea/workspace.xml | 40 ++++++++++++++++- LinkedList/Delete Nth node from end.java | 56 ++++++++++++------------ 2 files changed, 66 insertions(+), 30 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index cc9c7e9..6a4a90e 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -1,7 +1,36 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/LinkedList/Delete Nth node from end.java b/LinkedList/Delete Nth node from end.java index e3b80dc..9dc9b88 100644 --- a/LinkedList/Delete Nth node from end.java +++ b/LinkedList/Delete Nth node from end.java @@ -1,31 +1,31 @@ //This is method to delete Nth node from end of the linked list. //if method cannot have access to head then you have to pass head to function.Here I am not passing head as my linked list having access to head. -public void deleteNthFromEnd(int n){ - if(head == null){ - System.out.println("List is Empty."); - return; - } - if(head.next == null){ - head = null; - return; - } - int size = 0; - Node curr = head; - while(curr != null){ - curr = curr.next; - size++; - } - if(n == size){ - head = head.next; - return; - } - int searchIndex = (size-n)+1; - Node prev = head; - int i = 1; - while(i < searchIndex-1){ - prev = prev.next; - i++; - } - prev.next = prev.next.next; - } +//public void deleteNthFromEnd(int n){ +// if(head == null){ +// System.out.println("List is Empty."); +// return; +// } +// if(head.next == null){ +// head = null; +// return; +// } +// int size = 0; +// Node curr = head; +// while(curr != null){ +// curr = curr.next; +// size++; +// } +// if(n == size){ +// head = head.next; +// return; +// } +// int searchIndex = (size-n)+1; +// Node prev = head; +// int i = 1; +// while(i < searchIndex-1){ +// prev = prev.next; +// i++; +// } +// prev.next = prev.next.next; +// }