I have this code which orders the numbers starting from the biggest one but its kinda confusing for me:
#include <iostream>
using namespace std;
int main()
{
const int n=5;
int i, j, t, a[n]={15,9,8,7,5};
cout << "a[]={";
for(i=0; i<n; i++) cout << a[i] << " ";
cout << "} \n\n";
for(i=0; i<n-1; i++)
for(j=i+1; j<n; j++)
if(a[i]>a[j]){
t=a[i];
a[i]=a[j];
a[j]=t;
}
cout << "Pas radhitjes inkrementuese \n\n"
<< "a[]={";
for(i=0; i<n; i++) cout << a[i] << " ";
cout << "} \n\n";
cin.get();cin.get();
return 0;
}
Is there any other way to order numbers from 1 array, starting from the biggest/lowest number?
Well there is the selection sort, insertion sort, merge sort, quick sort, heap sort, etc. You can find a lot of information regarding the particular implementation around the web. If you want an easy way without regards to the actual implementation of the sorting algorithm, you can use
std::sortto accomplish this.