#include "frequencyString.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct hashnode {
int num;
char key;
};
struct hashnode* hash[256];
int compare(void* a, void* b) {
struct hashnode* p = *(struct hashnode**)a;
struct hashnode* q = *(struct hashnode**)b;
return (q->num - p->num);
}
char* frequencySort(const char* s) {
char* ret = (char *)malloc(strlen(s) + 1);
int len = 0;
for (int i = 0; i < 256; i++) {
hash[i] = (struct hashnode*)malloc(sizeof(struct hashnode*));
hash[i]->num = 0;
}
for (int i = 0; i < strlen(s); i++) {
int id = s[i];
hash[id]->key = s[i];
hash[id]->num++;
}
int(*fp)(void*, void*);
fp = &compare;
qsort(hash, 256, sizeof(struct hashnode*),( _CoreCrtNonSecur
qsort 函数中_CoreCrtNonSecureSearchSortCompareFunction问题
最新推荐文章于 2021-08-20 12:05:50 发布