Commit 7af41a1c authored by ATLA THARUN TEJA's avatar ATLA THARUN TEJA

change implementation to insertion-sort

parent 6b3ddc6b
...@@ -4,20 +4,48 @@ ...@@ -4,20 +4,48 @@
using namespace std; using namespace std;
vector<int> sort_custom(vector<int> c){ vector<int> sort_custom(vector<int> c){
bool pass = false; //have we passed through the cay without a swap? unsigned int i, j;
int temp;
vector<int> sortedArray( c.size());
while (!pass){ sortedArray = c;
pass = true;
for (int i=0; i<c.size()-1; i++){ int max;
if (c[i] > c[i+1]){
pass = false; for(i = 0; i<c.size();i++){
temp = c[i];
c[i] = c[i+1]; for(j = i; j<c.size();j++){
c[i+1] = temp; if(sortedArray[i] < sortedArray[j]){
int tmp;
tmp = sortedArray[i];
sortedArray[i] = sortedArray[j];
sortedArray[j] = tmp;
}
}
} }
return sortedArray;
}
int main() {
srand(time(NULL));
int n;
unsigned int i;
vector<int> nums;
cin>>n;
for(i = 1; i <= n; i++){
int element;
cin>>element;
nums.push_back(element);
} }
vector<int> sortedNums = sort_custom(nums);
for(i =0;i<sortedNums.size(); i++){
cout << sortedNums[sortedNums.size()-i-1] << " ";
} }
return c;
return 0;
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment