Page 302 - Cs_withBlue_J_C11_Flipbook
P. 302
32 }
33 }
34 System.out.println("The sorted arrays are: ");
35 for(i=0; i<nos; i++)
36 {
37 System.out.println(n[i]+ " : " + m[i]);
38 }
39 }
40 }
The output of the preceding program is as follows:
Enter a name: Megha
Enter marks: 78
Enter a name: Aryan
Enter marks: 6
Enter a name: Mamta
Enter marks: 78
Enter a name: Yuvraaj
Enter marks: 34
The sorted arrays are:
Aryan : 6
Yuvraaj : 34
Mamta : 78
Megha : 78
Selection Sort
Using this technique, the smallest element is first found and then the first element is interchanged with the smallest
element. Thus, the first element after one iteration is the smallest. Then the second element is compared and
interchanged with the second smallest element and swapped if required. This procedure keeps on continuing with
every element being compared, till the list finally gets sorted.
300300 Touchpad Computer Science-XI

