Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int *heap = new int[size];
- heap[0] = index[0];
- for(int i = 1; i < size; i++)
- {
- heap[i] = index[i];
- // Compare to the parent
- for (int j = i; j > 0; j >>= 1)
- if (customers[heap[(j - 1) >> 1]] < customers[heap[j]])
- { // Swap
- /*
- heap[j] ^= heap[(j - 1) >> 1];
- heap[(j - 1) >> 1] ^= heap[j];
- heap[j] ^= heap[(j - 1) >> 1];
- */
- int temp = heap[(j - 1) >> 1];
- heap[(j - 1) >> 1] = heap[j];
- heap[j] = temp;
- }
- else
- break;
- }
Add Comment
Please, Sign In to add comment