본문 바로가기

전체 글

(92)
[Data Structure 기초연습] HashTable - 해시 충돌 해결 - 개방 주소법 ( 제곱 탐사법 ) //해시 충돌 해결 - 개방 주소법 ( 제곱 탐사법 ) class MyHashTable3 extends MyHashTable{ MyHashTable3(int size){ super(size); } public void setValue(int key , int data){ int idx = this.getHash(key); if(this.elemCnt == this.table.length){ System.out.println("Hash table is full!"); return; }else if (this.table[idx] == null){ this.table[idx] = data; }else { int newIdx = idx; int cnt = 0; while (true){ newIdx = (newI..
[Data Structure 기초연습] HashTable - 해시 충돌 해결 - 개방 주소법 ( 선형 탐사법 ) import java.util.Hashtable; import java.util.Map; //해시 충돌 해결 - 개방 주소법 ( 선형 탐사법 ) class MyHashTable2 extends MyHashTable{ MyHashTable2(int size){ super(size); } public void setValue(int key , int data){ int idx = this.getHash(key); if (this.elemCnt == this.table.length){ System.out.println("Hash table is full!"); return; }else if (this.table[idx] == null){ //데이터가 할당되지 않은 상태라면 this.table[idx] = da..
[Java 기초연습] 프로그래머스 - 행성 X3 https://www.acmicpc.net/problem/2830 import java.io.*; public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int N = Integer.parseInt(br.readLine()); int[] binaryCnt = new int[20]; // 1,000,000의 이진 표현은 최대 20비트 필요 int name; long answer = 0L; for (int i = 0; i < N; i++) { name = Integer.parseInt(br...