-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcodinter2.1o(n).java
59 lines (53 loc) · 971 Bytes
/
codinter2.1o(n).java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import java.util.*;
public class Stringtest
{
public static class node //main函数是静态函数,只能调用静态类和静态方法
{public
int data;
node next;
}
public static void dupdelete(node l)
{
Hashtable<Integer, Boolean> table=new Hashtable<Integer,Boolean>();//<Key,Value>
node p=l;
table.put(p.data, true);
node n=p.next;
while(n!=null){
if(table.containsKey(n.data)){
p.next=n.next;
n=n.next;
}
else{
table.put(n.data, true);
p=n;
n=n.next;
}
}
}
public static void main(String [] argc)
{
node l=new node();
node p=l;
for(int i=1;i<10;i++){
for(int j=0;j<i;j++){
node temp=new node();
temp.data=j;
temp.next=null;
p.next=temp;
p=p.next;
}
}
p=l.next;
while(p!=null){
System.out.print(p.data);
p=p.next;
}
dupdelete(l.next);
System.out.print("\n");
p=l.next;
while(p!=null){
System.out.print(p.data);
p=p.next;
}
}
}