1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
|
#include<iostream>
using namespace std;
void quicksort(int v[100], int left, int right);
int v[100],q[100], x[100], n, i;
bool ok=false;
int main()
{
cout<<"n=";
cin>>n;
for(i=1; i<=n; i++)
{
cout<<"v["<<i<<"]=";
cin>>v[i];
}
for(i=1; i<=n; i++)
{
q[i]=v[i]%10;
}
quicksort(q, 1, n);
for(i=1; i<=n; i++)
{
for(int j=1; j<=n; j++)
{
if((q[i]==(v[j]%10)))
{
x[i]=v[j];
}
}
}
for(i=1; i<=n; i++)
{
cout<<x[i]<<" ";
}
}
void quicksort(int v[100], int left, int right)
{
int i,j,mid,aux;
i=left;
j=right;
mid=v[(left+right)/2];
while(i<=j)
{
while(v[i]<mid)
{
i++;
}
while(mid<v[j])
{
j--;
}
if(i<=j)
{
aux=v[i];
v[i]=v[j];
v[j]=aux;
i++;
j--;
}
}
if(left<j)
{
quicksort(v, left, j);
}
if(right>i)
{
quicksort(v, i, right);
}
}
|