Created
February 8, 2013 23:10
-
-
Save yolayne/4742714 to your computer and use it in GitHub Desktop.
Using insert_data and to_array functions from my Binary Search Tree project as my mystery sort on my Sorting Algorithms project.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This mystery_sort is going to use my insert_data and to_array function from BST project! | |
void mystery_sort(vector<int> &data) | |
{ | |
bt_node* top = init_node(data[0]); | |
// Looping through the data and adding it to my BST. | |
// ...Using my insert_data function which calls my insert function. | |
for (unsigned int i = 1; i < data.size(); i++) | |
insert_data(&top, data[i]); | |
// Need to set the size of an array before I can use it. | |
int arr [size(top)]; | |
// Now adding my items in the tree to an array. | |
to_array(top, arr); | |
// Now getting the sorted data out of the array and putting it back in the data vector! | |
for (int i = 0; i < size(top); i++) | |
data[i] = arr[i]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is it critical to use post-increment (
i++
)? If not, it's better to be changed to++i
, I suppose.