Created
January 23, 2020 17:14
-
-
Save raunaqsingh2020/fc3bec8690068dd4e9a3ecbd23ab3ecf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class freeResponse1 | |
{ | |
public freeResponse1() | |
{ | |
LinkedList list = new LinkedList(); | |
list.insert(list,1); | |
list.insert(list,6); | |
list.insert(list,2); | |
list.insert(list,3); | |
list.insert(list,4); | |
list.insert(list,4); | |
list.insert(list,5); | |
list.insert(list,6); | |
list.insert(list,7); | |
list.insert(list,4); | |
System.out.println("With Duplicates: "); | |
list.printList(list); | |
LinkedList withoutDuplicates = removeDuplicates(list); | |
System.out.println(); | |
System.out.println("Without Duplicates: "); | |
withoutDuplicates.printList(withoutDuplicates); | |
} | |
public LinkedList removeDuplicates(LinkedList original){ | |
LinkedList newList = new LinkedList(); | |
for(int i = 0; i < original.getSize(original); i++){ | |
if (newList.find(newList, original.get(original, i))==-1) { | |
newList.insert(newList, original.get(original, i)); | |
} | |
} | |
return newList; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment