void doSort( int n, int v[][2])
{
int i,j,k;
for (i = n; i > 1; i = i-1)
{ for (j=1; j<i; j = j+1)
{
if ( v[j][0] > v[j+1][0] )
{ k = v[j][0]; // swap key
v[j][0] = v[j+1][0];
v[j+1][0] = k;
k = v[j][1]; // swap data
v[j][1] = v[j+1][1];
v[j+1][1] = k;
}
}
}
}
Second sorting program
# shell – Shell sort v(1) … v(n) increasing
void doSort( int n, int v[][2])
{
int gap, i,j,jg, k;
for (gap = n/2; gap > 0; gap=gap/2)
{ for (i=gap+1; i<n; i++)
{ for (j = i-gap; j>0; j=j-gap)
{
jg = j + gap;
if ( v[j][0] < v[jg][0] )
{break;
}
else
{ k = v[j][0]; // swap key
v[j][0] = v[jg][0];
v[jg][0] = k;
k = v[j][1]; // swap data
v[j][1] = v[jg][1];
v[jg][1] = k;
}
}
}
}
}
/* Bubble Sort */
public class sortB
{
private sortB() {}
public void doSort( int n, int v[][])
{
int i,j,k;
for (i = n; i > 1; i = i-1)
{ for (j=1; j<i; j = j+1)
if ( v[j][0] > v[j+1][0] )
{ k = v[j][0]; // swap key
v[j][0] = v[j+1][0];
v[j+1][0] = k;
k = v[j][1]; // swap data
v[j][1] = v[j+1][1];
v[j+1][1] = k;
}
}
}
}
/* Shell Sort */
public class sortS
{
private sortS() {}
public void doSort( int n, int v[][])
{
int gap, i,j,jg, k;
for (gap = n/2; gap > 0; gap=gap/2)
{ for (i=gap+1; i<n; i++)
{ for (j = i-gap; j>0; j=j-gap)
{
jg = j + gap;
if ( v[j][0] < v[jg][0] )
{break;
}
else
{ k = v[j][0]; // swap key
v[j][0] = v[jg][0];
v[jg][0] = k;
k = v[j][1]; // swap data
v[j][1] = v[jg][1];
v[jg][1] = k;
}
}
}
}
}
}