Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.89 KB | None | 0 0
  1.         void PriorityQueue::percolateDown( unsigned short hole )
  2.         {
  3.             unsigned short start, child;
  4.             HeapVertex tmp = array[ hole ];
  5.  
  6.             for ( ; (hole * 4 - 2) <= currentSize; hole = child ) {
  7.               start = child = hole * 4 - 2;
  8.              
  9.               if (child != currentSize && array[child + 1].distance < array[child].distance )
  10.                 child++;
  11.               if (start + 1 < currentSize && array[start + 2].distance < array[child].distance )
  12.                child = start + 2;
  13.               if (start + 2 < currentSize  && array[start + 3].distance < array[child].distance)
  14.                 child = start + 3;
  15.  
  16.               if (child != hole && array[child].distance < tmp.distance)
  17.                 array[ hole ] = array[ child ];
  18.               else
  19.                 break;
  20.             }
  21.             array[ hole ] = tmp;
  22.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement