Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added tournament sorting issue #66 #100

Merged
merged 1 commit into from
Oct 15, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions sorting/Heap_sort/cpp/tournament_sorting.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// C++ program to implement tournament sort
// More info can be found: https://en.wikipedia.org/wiki/Tournament_sort


#include <iostream>
#include <vector>
using namespace std;

void sort(int arr[], int n)
{
int leafNodes[4];
int subTree[2];
int root;

for (int i = 0; i < 4; ++i)
{
leafNodes[i] = arr[i];
cout << leafNodes[i] << endl;
}

for(int i = 0; i < n - 1; ++i)
{
min(leafNodes[i], leafNodes[i+1]);
cout << "min of " << arr[i] << " and " << arr[i + 1] << " is " << min(arr[i], arr[i + 1]) << endl;

}
}

/* A utility function to print integers */
void printIntegers(int arr[], int n)
{
for(int i = 0; i < n; ++i)
{
cout << arr[i] << " ";
}
cout << "\n";
}

// Test program
int main()
{
int myInts[] = {12, 11, 9, 2, 6, 7, 10, 1, 3, 4, 8, 5};
int size = sizeof(myInts)/sizeof(myInts[0]);

sort(myInts, size);

cout << "Sorted array is \n";
printIntegers(myInts, size);
}