Help With Costructing Selection sort?

Help With Costructing Selection sort?

Using a selection sort, for each entry in the array, display the original index of the first dimension, the second dimension's value, and the first dimension's value on a single line separated by : (colon) sorted by the first dimension.

I got the two dimensional array figure out just dont know how to incorporate the above question.

Thanks in advance!

View Answers

July 12, 2012 at 11:56 AM

Please visit the following link:

Java Selection Sort


July 14, 2012 at 10:48 PM

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
public class SelectionSort {

 /**
  * @Author [Chandrasekhara Kota][1]
  */
 public static void main(String[] args) {
  int arr[]={9,1,8,5,7,-1,6,0,2,2718};
  int sortedArr[]=selectionSort(arr);
  for (int i = 0; i <sortedArr.length; i++) 
  { 
   System.out.println(sortedArr[i]);
  }

 }

 private static int[] selectionSort(int[] arr) { 

  int  minIndex, tmp; 
  int n = arr.length; 
  for (int i = 0; i < n - 1; i++) 
  { 
              minIndex = i; 
              for (int j = i + 1; j < n; j++) 
                   if (arr[j] < arr[minIndex]) 
                        minIndex = j; 
              if (minIndex != i) { 
                    tmp = arr[i]; 
                    arr[i] = arr[minIndex]; 
                    arr[minIndex] = tmp; 
              } 
        }
  return arr; 
 }
}









Related Tutorials/Questions & Answers:
Help With Costructing Selection sort?
need help with two dimensional array that takes input from user and bubble sorts and selections sorts
Advertisements
ModuleNotFoundError: No module named 'sorti'
ModuleNotFoundError: No module named 'Sorty'
sir plz help in design a jsp page whichis as follow username [_____] select [__>]password [_____] after selection then onlypassword text box is visible
ModuleNotFoundError: No module named 'python-sorts'
ModuleNotFoundError: No module named 'sorts-pr'
Selection based on other selection in jsp
Selection Using JoptionPane
single selection of chechbox among multiple selection when in a loop.
insert multiple selection - Java
checkbox selection in jsp
ModuleNotFoundError: No module named 'selection'
help
help
help
HELP
Image Selection - Swing AWT
changing selection color of <button>
Help...
Help
Help!
help
Help
help
help!!!!!!!!!!!!!!!!!!
interrelated two selection box
highlight uitableviewcell on selection
ModuleNotFoundError: No module named 'model-selection'
ModuleNotFoundError: No module named 'blacken-selection'
ModuleNotFoundError: No module named 'causal-selection'
ModuleNotFoundError: No module named 'causal-selection'
ModuleNotFoundError: No module named 'model-selection'
selection box linked with textarea
Displaying files on selection of date.
Selection With Ajax and JSP
else if (selection = * 'M'); - Java Beginners
Table-chart selection
enable text box and label on selection
Selection Sort in Java
Importance of Recruitment and Selection
ModuleNotFoundError: No module named 'colcon-package-selection'
ModuleNotFoundError: No module named 'ecg-feature-selection'
ModuleNotFoundError: No module named 'naive-feature-selection'
ModuleNotFoundError: No module named 'odoo10-addon-pos-lot-selection'
ModuleNotFoundError: No module named 'odoo10-addon-pos-lot-selection'
ModuleNotFoundError: No module named 'odoo10-addon-pos-lot-selection'
ModuleNotFoundError: No module named 'odoo11-addon-pos-lot-selection'
ModuleNotFoundError: No module named 'rpi-feature-selection-toolbox'
ModuleNotFoundError: No module named 'branch-and-bound-feature-selection'

Ads