Created
April 24, 2019 16:40
-
-
Save godtaehee/fccf1a50e690080b7f05fde2ecddae92 to your computer and use it in GitHub Desktop.
#Algorithm Sort
This file contains hidden or 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
#include <iostream> | |
using namespace std; | |
int scount = 0; | |
void treeInsert(int arr[], int t , int x){ | |
scount++; | |
int left = 2 * t + 1; | |
int right = 2 * t + 2; | |
if(arr[t] == 0){ | |
arr[t] = x; | |
arr[left] = 0; | |
arr[right] = 0; | |
return; | |
} | |
if(x < arr[t]) | |
treeInsert(arr, left, x); | |
else | |
treeInsert(arr, right, x); | |
} | |
int main(){ | |
int n; | |
int x; | |
cin >> n; | |
if(n < 1 || n > 100) | |
return 0; | |
int arr[100] = {0}; | |
for(int i = 0; i < n; i++){ | |
cin >> x; | |
treeInsert(arr, 0, x); | |
} | |
/* for(int i =0; i < n; i++) | |
cout << arr[i] << ' ';a | |
cout << endl;*/ | |
cout << scount; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment