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

change implementation to insertion-sort

parent 6b3ddc6b
......@@ -4,20 +4,48 @@
using namespace std;
vector<int> sort_custom(vector<int> c){
bool pass = false; //have we passed through the cay without a swap?
int temp;
while (!pass){
pass = true;
for (int i=0; i<c.size()-1; i++){
if (c[i] > c[i+1]){
pass = false;
temp = c[i];
c[i] = c[i+1];
c[i+1] = temp;
}
unsigned int i, j;
vector<int> sortedArray( c.size());
sortedArray = c;
int max;
for(i = 0; i<c.size();i++){
for(j = i; j<c.size();j++){
if(sortedArray[i] < sortedArray[j]){
int tmp;
tmp = sortedArray[i];
sortedArray[i] = sortedArray[j];
sortedArray[j] = tmp;
}
}
}
}
return c;
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 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