The original location does not change,
For example: array int a [5]={100,80,7,44,17}
After sorting the results as follows:
{44 reached, 17100, 7}
Sorting before even in 0, 1 and 3, even after sorting is still in the 0, 1 and 3,
Before ordering the odd in 2 and 4, after the sorting odd number is still in the 2 and 4,
Public class Csort {
Public void upbubble (int a [], int n) {
for (int i=0; i
for (int j=0; j
int temp;
Temp=a, [j].
A [j]=a, a + 1 bonus to [j].
A=\ [j + 1];
flag=false;
}
}
If (flag)
break;
}
}
Public void downbubble (int a [], int n) {
for (int i=0; i
for (int j=0; j
int temp;
Temp=a, [j].
A [j]=a, a + 1 bonus to [j].
A=\ [j + 1];
flag=false;
}
}
If (flag)
break;
}
}
Public void jobubble (int a [], int n) {
//finish this function
}
Public void display (int a [], int n) {
System.out.println();
for (int i=0; i
System.out.println();
}
}
Public class Cmain {
Public static void main (String [] args) {
Int a, [].
A=new int [20].
A [0]=50;
A [1]=17;
A [2]=2;
A [3]=34;
A [4]=401;
A [5]=157;
A, [6]=15.
A [7]=81;
A [8]=52;
A [9]=63;
A [10]=64;
A [11]=95;
A [12]=51;
A [13]=82;
A [14]=33;
A [15]=65;
A [16]=911;
A, [17]=22.
A [18]=83;
A [19]=104;
Csort BB=new Csort ();
System. The out. Println (" original array is: ");
BB. The display (a, 20);
System. Out. Println (" odd descending even after sorting result is: ");
BB. Jobubble (a, 20);
BB. The display (a, 20);
}
}
This topic how to write ah o
CodePudding user response:
First traversal access t location information such as what you said x=,0,1,0,1 [0] 0 odd number is an even number 1 represented, and get a new array,80,44 [100] b [17, 7].Sorting, respectively, a=b=[44,80,100] [17, 7]
Second traversal x and obtain a or b's current location data, the subscript of a and b are calculated respectively
CodePudding user response:
Thank youPublic void jobubble (int a [], int n) {
//finish this function
Int [] x=new int [n].
Int [] arr1=new int [n].
Int [] arr2=new int [n].
for(int i=0; i
[I] x=0;
Arr1=[I] a [I];
}
The else {
[I] x=1;
Arr2=[I] a [I];
}
}
for (int i=0; i
System.out.println();
for (int i=0; i
System.out.println();
for (int i=0; i
}
Then how to separate t, in the two arrays, the result is that after I separated from
1 0 0 1 1 1 1 0 0 0 1 1 1 1 1 0 0 0 1
50 34 52 0 0 0 0 0 0 2 22 64 82 0 0 0 0 0 0, 104
17 401, 157, 15 81 0 0 0 0 0 95 63 51 0 33 65 911 0, 83
If can't achieve this function, how should do