기타/What I Learned

[TIL] 자료구조 - 내부 클래스

가죽방패 2022. 5. 25. 10:11

※ 내부 클래스

- 체인 해시는 해시 요소마다 키와 그에 해당하는 값이 들어있는데 키와 값을 저장하기 위한

내부 클래스는 다음 예시와 같다.

 

public class Hash<K, V> implements Hashl<K, V>{
	class HashElement<K, V> implements Comparable <HashElement<K, V>>{
    // 키와 값 정의
    K key;
    V value;
    public HashElement(K key, V value){
    	this.key = key;
        this.value = value;
    }
	//compareTo 함수
    public int compareTo(HashElement<K, V> h)
    	return (((Comparable<K>h.key).compareTo(this.key))
    }
}