JOIN
Get Time
forums   
Search | Watch Thread  |  My Post History  |  My Watches  |  User Settings
View: Flat (newest first)  | Threaded  | Tree
Previous Thread  |  Next Thread
Heapsort Example : Clarification of where output needs to be stored | Reply
int[] result = new int[data.Length];
for (int i = 0; i < data.Length; i++)
data[i] = h.RemoveLowest();

Wrt,above snippet of code that was used in example for Heapsort.
The author takes data from data array, makes a heap structure out of it stored in h structure.
Finally while storing the sorted array by using h.RemoveLowest();
the sorted output can be stored back in the input array data, in that case the statement int[] result = new int[data.Length];
is not needed.

If one wants to preserve unordered input array data , then the data is to be written to the allocated result array.

Allocating result array , but storing output back in data array is inefficient.

Regards
Dilip
RSS