Advertisement
Guest User

Untitled

a guest
Feb 27th, 2015
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. linked* sorted_huff_list(int* xs) {
  2. linked** listad = malloc(sizeof(linked*));
  3. *listad = NULL;
  4. int i;
  5. for (i = 0; i < 27; i++) {
  6. if (xs[i] != 0)
  7. {
  8. huff* new = huff_singleton(i+'A', xs[i]);
  9. sorted_insert(new, listad);
  10. } else {;}
  11. }
  12. return *listad;
  13. }
  14.  
  15. void sorted_insert(huff* h, linked** l) {
  16. if(*l == NULL) {
  17. linked* new = malloc(sizeof(linked));
  18. new->h = h;
  19. new->next = NULL;
  20. *l = new;
  21. } else {
  22. linked* list = *l;
  23. if ((list->next == NULL) && (huff_weight(h) > huff_weight(list->h))) {
  24. linked* new2 = malloc(sizeof(linked));
  25. new2->h = h;
  26. new2->next = NULL;
  27. list->next = new2;
  28. } else if ( huff_weight(h) > huff_weight(list->h) ) {
  29. linked* next = list->next;
  30. sorted_insert(h, &next);
  31. } else
  32. {
  33. linked* newe = malloc(sizeof(linked));
  34. newe->h = list->h;
  35. newe->next = list->next;
  36. list->h = h;
  37. list->next = newe;
  38. }
  39. }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement