Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2018
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. bool MyHeap::display()
  2. {
  3. if(!heapLength)
  4. return 0;
  5. int specialLevel = 2;
  6. int elementsToDisplay = 1;
  7. int index = 0;
  8. while (specialLevel * 2 <= heapLength)
  9. specialLevel *= 2;
  10. specialLevel--;
  11. for(; specialLevel > 0 && heapLength > 1; specialLevel/=2, elementsToDisplay *= 2)
  12. {
  13. cout << " ";
  14. for (int x = 0; x < elementsToDisplay; x++, index++)
  15. {
  16. if(x == 0)
  17. {
  18. for (int space = 0; space < specialLevel / 2; space++)
  19. cout << " ";
  20. }
  21. else
  22. {
  23. for (int space = 0; space < specialLevel; space++)
  24. cout << " ";
  25. }
  26. printf("%3d ",mainHeap[index]);
  27. }
  28. cout << endl;
  29. }
  30. for (; index < heapLength; index++)
  31. {
  32. printf("%3d ", mainHeap[index]);
  33. }
  34. cout << endl;
  35.  
  36. return 1;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement