Skip to content

Commit

Permalink
Create InterchangeSort.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
trungqudinh authored Oct 20, 2019
1 parent dde9727 commit 06dbde1
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions C++/InterchangeSort.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include <iostream>
#include <string>

using namespace std;

void swap(int &a, int &b)
{
int x = a;
a = b;
b = x;
}

void interchange_sort(int a[], int n)
{
for (int i = 0; i < n-1;i++)
for (int j = i + 1; j < n;j++)
if (a[i]>a[j])
swap(a[i], a[j]);
}

int main()
{
int n =10;
int a[] = {8, 6, 3, 7, 1, 8, 2, 8, 1, 11};
interchange_sort(a, n);
for(int i = 0; i < n; i++)
{
cout << a[i] << " ";
}
return 0;
}

0 comments on commit 06dbde1

Please sign in to comment.