Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. void pretty_print_heap(FILE* out, const int* v, unsigned n)
  2. {
  3. int w = ints_width(v, n - 1);
  4. int count = 0;
  5. int nbline = 0;
  6. count++;
  7. for (unsigned j = 0; j < n; j = 2 * j + 1)
  8. {
  9. nbline++;
  10. }
  11. int plus = w + 1;
  12. int t = (plus) * pow(2, nbline - 1);
  13. int g = 0;
  14. for (unsigned i = 0; i < n; i = i)
  15. {
  16. int did = 0;
  17. int s = t / count - w;
  18. int to_floor = (s / 2);
  19. int nbspaces = floor(to_floor);
  20. for (int h = 0; h < nbspaces; h++)
  21. fprintf(out, " ");
  22. int test = g;
  23. for (int l = g; l < count + test && i < n; l++)
  24. {
  25. if (g != 0 && did == 1)
  26. {
  27. for (int k = 0; k < s; k++)
  28. fprintf(out, " ");
  29. }
  30. for (int u = int_width(v[l]); u < w; u++)
  31. fprintf(out, " ");
  32. i++;
  33. g++;
  34. did = 1;
  35. fprintf(out,"%d" ,v[l]);
  36. }
  37. fprintf(out, "\n");
  38. count = count * 2;
  39. }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement