Skip to content

Commit fe99386

Browse files
authored
Merge pull request #42 from Data-Structure-Study/yoonexample
Table 자료구조 공부
2 parents 08a3d0c + d559628 commit fe99386

File tree

4 files changed

+112
-0
lines changed

4 files changed

+112
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package table;
2+
3+
public class Person {
4+
5+
private final int id;
6+
private final String name;
7+
private final String address;
8+
9+
public Person(int id, String name, String address) {
10+
this.id = id;
11+
this.name = name;
12+
this.address = address;
13+
}
14+
15+
public void printPersonInfo() {
16+
System.out.println(
17+
"ID: " + this.getId() + " / 이름: " + this.getName() + " / 주소: " + this.getAddress());
18+
}
19+
20+
public int getId() {
21+
return id;
22+
}
23+
24+
public String getName() {
25+
return name;
26+
}
27+
28+
public String getAddress() {
29+
return address;
30+
}
31+
}
+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package table;
2+
3+
import static table.SlotStatus.DELETED;
4+
import static table.SlotStatus.EMPTY;
5+
import static table.SlotStatus.INUSE;
6+
7+
public class Slot<K, V> {
8+
9+
private K key;
10+
private V value;
11+
private SlotStatus status;
12+
13+
public Slot() {
14+
this.status = EMPTY;
15+
}
16+
17+
public void insertData(K key, V value) {
18+
this.key = key;
19+
this.value = value;
20+
this.status = INUSE;
21+
}
22+
23+
public V deleteData(V value) {
24+
V returnValue = this.value;
25+
this.key = null;
26+
this.value = null;
27+
this.status = DELETED;
28+
return returnValue;
29+
}
30+
31+
public V getValue() {
32+
return this.value;
33+
}
34+
35+
public K getKey() {
36+
return this.key;
37+
}
38+
39+
public SlotStatus getStatus() {
40+
return status;
41+
}
42+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package table;
2+
3+
public enum SlotStatus {
4+
EMPTY, DELETED, INUSE
5+
}
+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package table;
2+
3+
/**
4+
* 테이블 자료구조의 인터페이스, ADT
5+
*
6+
* @param <K> Key 타입에 사용될 타입 파라미터
7+
* @param <V> Value 타입에 사용될 타입 파라미터
8+
*/
9+
public interface Table<K, V> {
10+
11+
/**
12+
* 테이블에 key로 value를 저장합니다.
13+
*
14+
* @param key key 역할을 할 값
15+
* @param value value 역할을 할 값
16+
*/
17+
void insert(K key, V value);
18+
19+
/**
20+
* 테이블에 key값으로 저장되어있는 value를 찾습니다.
21+
*
22+
* @param key 검색에 사용될 key 값
23+
* @return key값에 해당하는 value, null 가능
24+
*/
25+
V search(K key);
26+
27+
/**
28+
* 테이블에 key값으로 저장되어있는 value를 찾아 테이블에서 제거하고, value를 반환합니다.
29+
*
30+
* @param key 검색에 사용될 key 값
31+
* @return key값에 해당하는 value, null 가능
32+
*/
33+
V delete(K key);
34+
}

0 commit comments

Comments
 (0)