Skip to content

Commit 55d3082

Browse files
committed
Linked List Updates
Linked List Updates
1 parent 1b2e2ca commit 55d3082

File tree

4 files changed

+58
-0
lines changed

4 files changed

+58
-0
lines changed
Binary file not shown.
Binary file not shown.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*Copyright (c) Dec 22, 2014 CareerMonk Publications and others.
2+
* E-Mail : info@careermonk.com
3+
* Creation Date : 2015-01-10 06:15:46
4+
* Last modification : 2006-05-31
5+
by : Narasimha Karumanchi
6+
* File Name : RemoveDuplicatesBruteForce.java
7+
* Book Title : Data Structures And Algorithms Made In Java
8+
* Warranty : This software is provided "as is" without any
9+
* warranty; without even the implied warranty of
10+
* merchantability or fitness for a particular purpose.
11+
*
12+
*/
13+
14+
15+
package chapter3linkedlists;
16+
17+
public class RemoveDuplicatesBruteForce {
18+
public static void removeDuplicates2(ListNode head) {
19+
ListNode curr = head;
20+
if(curr == null || curr.getNext() == null) {
21+
return; // 0 or 1 nodes in the list so no duplicates
22+
}
23+
ListNode curr2;
24+
ListNode prev;
25+
while(curr != null) {
26+
curr2 = curr.getNext();
27+
prev = curr;
28+
while(curr2 != null) {
29+
// check and see if curr and curr2 values are the same, if they are then delete curr2
30+
if(curr.getData()==curr2.getData()) {
31+
prev.setNext(curr2.getNext());
32+
}
33+
prev = curr2;
34+
curr2 = curr2.getNext();
35+
}
36+
curr = curr.getNext();
37+
}
38+
}
39+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*Copyright (c) Dec 22, 2014 CareerMonk Publications and others.
2+
* E-Mail : info@careermonk.com
3+
* Creation Date : 2015-01-10 06:15:46
4+
* Last modification : 2006-05-31
5+
by : Narasimha Karumanchi
6+
* File Name : RemoveDuplicatesHashing.java
7+
* Book Title : Data Structures And Algorithms Made In Java
8+
* Warranty : This software is provided "as is" without any
9+
* warranty; without even the implied warranty of
10+
* merchantability or fitness for a particular purpose.
11+
*
12+
*/
13+
14+
15+
package chapter3linkedlists;
16+
17+
public class RemoveDuplicatesHashing {
18+
19+
}

0 commit comments

Comments
 (0)