반응형
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
|
반응형
'Algorithm' 카테고리의 다른 글
알고리즘 공부할것들 (0) | 2020.04.02 |
---|---|
LCA(Lowest Common Ancestor) (0) | 2020.03.31 |
파라메트릭 (0) | 2020.03.13 |
JAVA : nextPermutation 다음순열 (2) | 2020.03.12 |
TreeSet : 트리에서 인덱스 번호 반환, 범위 값출력 (0) | 2020.03.06 |