Algorithm
LinkedList : java
하이후에호
2020. 3. 18. 14:17
반응형
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
|
public class Linkedlist {
static class Node{
Object data;
Node link;
public Node(Object data) {
this.data = data;
}
public Node(Object data, Node link) {
super();
this.data = data;
this.link = link;
}
@Override
public String toString() {
return "Node [data=" + data + ", link=" + link + "]";
}
}
private Node head; // 첫노드 자신
public void addFirstNode(Object data) {
head = new Node(data,head);
}
public Node getNode(Object data) {
Node curNode = head;
while(curNode != null) {
return curNode;
}
curNode = curNode.link;
}
return null;
}
public void printList() {
Node curNode = head;
while(curNode !=null) {
curNode = curNode.link;
}
System.out.println();
}
public static void main(String[] args) {
Linkedlist list = new Linkedlist();
list.addFirstNode("김태희");
list.printList();
list.addFirstNode("이동욱");
list.printList();
list.addFirstNode("이지아");
list.printList();
System.out.println(list.getNode("김태희"));
System.out.println(list.getNode("이동욱"));
}
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
|
반응형