Created
April 28, 2016 00:21
-
-
Save AntonisFK/981e06b656176dbab9551253d04111d7 to your computer and use it in GitHub Desktop.
Removing duplicates from an unsorted link list
This file contains 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
function removeDuplicates(SSL){ | |
if(this.head === null){ | |
return false; | |
}else { | |
var current = this.head; | |
var obj = {}; | |
while(current.next !== null){ | |
// going to use an object to check if | |
if(current.next.value in obj){ | |
//we are going to do the swap | |
current.next = current.next.next; | |
} | |
// create a key with the value, rememeber there can not be duplicate keys | |
obj[current.value] = 1; | |
//traverse down the link list | |
current = current.next; | |
} | |
} | |
return SSL; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment