-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
95 lines (80 loc) · 2.15 KB
/
Copy pathMain.java
File metadata and controls
95 lines (80 loc) · 2.15 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package NodeList;
import java.awt.peer.TrayIconPeer;
import javax.swing.event.ListSelectionEvent;
import Java_algoirthm.Strategy;
import Part_1.practice_1_1_13;
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
Student stu1=new Student("111","111",111);
Student stu2=new Student("222","222",222);
Student stu3=new Student("333", "333", 333);
Student stu4=new Student("444", "444", 444);
// SLNode sl=new SLNode();
// SLNode sl2=new SLNode();
// SLNode sl3=new SLNode();
// SLNode sl4=new SLNode();
//
// sl.setData(stu1);
// sl.setNext(sl2);
//
// sl2.setData(stu2);
// sl2.setNext(sl3);
//
// sl3.setData(stu3);
// sl3.setNext(sl4);
//
// sl4.setData(stu4);
//
// SLNode head=new SLNode();
// head=sl;
//
// //遍历
// while(head.hasNext()) {
// System.out.println(head.getData());
// head=head.getNext();
// }
// System.out.println(head.getData());
StudentStrategy studentStrategy=new StudentStrategy();
ListSLinked listSLinked=new ListSLinked(studentStrategy);
try {
listSLinked.insert(0, stu1);
listSLinked.insert(1, stu2);
listSLinked.insertBefore(stu1, stu3);
listSLinked.insertAfter(stu3, stu4);
} catch (OutOfBoundayException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally {
listSLinked.PrintLinkedList();
}
System.out.println("removing.......................");
try {
listSLinked.remove(3);
}catch (OutOfBoundayException e) {
// TODO: handle exception
e.printStackTrace();
}finally {
listSLinked.PrintLinkedList();
}
Object resultnode;
try {
resultnode = (Object)listSLinked.get(2);
System.out.println(resultnode);
} catch (OutOfBoundayException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally {
System.out.println("end");
}
try {
Student stu5=new Student("555","555",555);
listSLinked.replace(2, stu5);
}catch (OutOfBoundayException e) {
// TODO: handle exception
e.printStackTrace();
}finally {
listSLinked.PrintLinkedList();
}
}
}