#leetcode 347
숫자 대신 단어들로 구현하였다.
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <string.h>
#include "function.h"
#define STRING_SIZE 100
int main() {
BUCKET* hash = (BUCKET*)calloc(ALPHABET_SIZE, sizeof(BUCKET));
assert(hash != NULL);
HeapType* heap = (HeapType*)calloc(1, sizeof(HeapType));
assert(heap != NULL);
int NumOfWords;
char* sep = NULL;
char* str = NULL;
int len;
printf("단어들을 입력하세요\n");
str = (char*)calloc(STRING_SIZE, sizeof(char));
assert(str != NULL);
fgets(str,STRING_SIZE*sizeof(char), stdin);
len = strlen(str);
str[len-1] = '\0';
sep = strtok(str, " ");
while (sep != NULL) {
InsertBucket(hash, sep);
sep = strtok(NULL, " ");
}
NumOfWords=printHashMap(hash);
heap->node = (char**)calloc(NumOfWords+1, sizeof(char*));
assert(heap->node != NULL);
int i;
InsertData(heap, hash, NumOfWords);
printHeap(heap);
printf("상위 몇 개의 데이터를 출력하시겠습니까?\n");
int rank;
scanf("%d", &rank);
for (i = 1; i <= rank; i++) {
printf("%s ", deleteData(heap, hash));
}
//cat rabbit cat dog dog cat cat rabbit bird rabbit
//apple banana banana watermelon apple apple strawberry banana banana
getchar();
return 0;
}