15,662,459 members
1.00/5 (1 vote)
See more:
C++
```#include<iostream.h>

(main) void
{
int i, j, first, temp;
int numLength = num.length( );
for (i= numLength - 1; i > 0; i--)
{
first = 0;
for (j=1; j<=i; j++)
{
if (num[j] < num[first])
first = j;
}
temp = num[first];
num[first] = num[i];
num[i] = temp;
}
return;
}```

Code block added, HTML encoded - OriginalGriff[/edit]
Posted
Updated 12-May-20 19:27pm
v4
Richard C Bishop 8-Jan-13 14:23pm
This is not a question. Elaborate on your issue and explain what you are trying to accomplish. Then, form a specific question on what you need help with.
OriginalGriff 8-Jan-13 14:23pm
This is not a good question - we cannot work out from that little what you are trying to do.
You seem to have forgotten to tell us what your problem is...
Use the "Improve question" widget to edit your question and provide better information.
i need slection sort example plz share who its work

## Solution 3

Your code won't compile, even on the ancient compiler you are using (why don't you use a more modern `C++` compiler?).

You probably mean:
C++
```#include <iostream.h>

// the selection sort function
void sort(int num[], int numLength);

// usage sample
int main()
{
int v[] =  {0,7,-5, 10000, 45};
const int SIZE = sizeof(v)/sizeof(v[0]);
sort(v, SIZE);
for (int i=0; i<SIZE; i++)
cout << v[i] << " ";
cout << endl;
}
// sort implementation
void sort(int num[], int numLength)
{
int i, j, first, temp;
if ( numLength < 2) return;

for (i = numLength - 1; i > 1; i--)
{
first = 0;
for (j=1; j<=i; j++)
{
if (num[j] < num[first])
first = j;
}
temp = num[first];
num[first] = num[i];
num[i] = temp;
}```

nv3 8-Jan-13 16:15pm
Hey, you are way too good to these guys who are trying to get their homework done :-)
CPallini 9-Jan-13 3:01am
:-)

## Solution 2

Looks like a homework to me. but google search would list your result.

Check here[^]

## Solution 1

This is not a question at all. The one thing I will say is, iostream.h is not C++. Just include iostream without the .h. Apart from that, this is a code dump. If you have a question, edit this post, and ask it. If not, it will be deleted.

## Solution 4

My code to sort an array in descending order by selection sort:-
.
.
.
```#include <bits/stdc++.h>
using namespace std;

void swap(int *xp, int *yp)
{
int temp = *xp;
*xp = *yp;
*yp = temp;
}

void selectionSort(int arr[], int n)
{
int i, j, max_idx;

for (i = 0; i < n-1; i++)
{
max_idx = i;
for (j = i+1; j < n; j++)
if (arr[j] > arr[max_idx])
max_idx = j;
swap(&arr[max_idx], &arr[i]);
}
}
void printArray(int arr[], int size)
{
int i;
for (i=0; i < size; i++)
cout << arr[i] << " ";
cout << endl;
}

// Driver program to test above functions
int main()
{
int arr[] = {64, 25, 12, 22, 11};
int n = sizeof(arr)/sizeof(arr[0]);
selectionSort(arr, n);
cout << "Sorted array: \n";
printArray(arr, n);
return 0;
}  ```

v4