Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- linked* sorted_huff_list(int* xs) {
- linked** listad = malloc(sizeof(linked*));
- *listad = NULL;
- int i;
- for (i = 0; i < 27; i++) {
- if (xs[i] != 0)
- {
- huff* new = huff_singleton(i+'A', xs[i]);
- sorted_insert(new, listad);
- } else {;}
- }
- return *listad;
- }
- void sorted_insert(huff* h, linked** l) {
- if(*l == NULL) {
- linked* new = malloc(sizeof(linked));
- new->h = h;
- new->next = NULL;
- *l = new;
- } else {
- linked* list = *l;
- if ((list->next == NULL) && (huff_weight(h) > huff_weight(list->h))) {
- linked* new2 = malloc(sizeof(linked));
- new2->h = h;
- new2->next = NULL;
- list->next = new2;
- } else if ( huff_weight(h) > huff_weight(list->h) ) {
- linked* next = list->next;
- sorted_insert(h, &next);
- } else
- {
- linked* newe = malloc(sizeof(linked));
- newe->h = list->h;
- newe->next = list->next;
- list->h = h;
- list->next = newe;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement