Skip to content

Instantly share code, notes, and snippets.

@yolayne
Created February 8, 2013 23:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yolayne/4742714 to your computer and use it in GitHub Desktop.
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 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];
}
@UnoYakshi
Copy link

Is it critical to use post-increment (i++)? If not, it's better to be changed to ++i, I suppose.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment