Last active
August 29, 2015 14:02
-
-
Save bitcpf/7ce6a0976d775bd00724 to your computer and use it in GitHub Desktop.
CC_2_1
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
/* | |
Created by bitcpf | |
*/ | |
import java.util.*; | |
public class Removedup { | |
public static <Item> LinkedList<Item> Rmdup(LinkedList<Item> in_link){ | |
HashSet<Item> set = new HashSet<Item>(); | |
LinkedList<Item> newlist = new LinkedList<Item>(); | |
for(Item item: in_link){ | |
if(set.add(item)){ | |
newlist.add(item); | |
} | |
} | |
return newlist; | |
} | |
public static void main(String[] args){ | |
LinkedList<Integer> testcase = new LinkedList<Integer>(); | |
testcase.add(1); | |
testcase.add(3); | |
testcase.add(5); | |
testcase.add(6); | |
testcase.add(4); | |
testcase.add(2); | |
testcase.add(3); | |
testcase.add(2); | |
System.out.println(testcase.toString()); | |
System.out.println(Rmdup(testcase).toString()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment