John Delmark Aguilar
Would you like to react to this message? Create an account in a few clicks or log in to continue.
John Delmark Aguilar

Personal Forum
 
HomeSearchLatest imagesRegisterLog in

 

 Data Sorting: SelectionSort Java

Go down 
AuthorMessage
dElmARk
Admin
Admin
dElmARk


Posts : 92
Join date : 09/04/2012

Data Sorting: SelectionSort Java Empty
PostSubject: Data Sorting: SelectionSort Java   Data Sorting: SelectionSort Java Icon_minitimeTue Oct 23, 2012 1:03 pm

SelectionSort Java

Code:
public class SelectionSort
{
 public static void main(String A[])
 {
  int i;
  int array[]={12,9,4,99,120,1,3,10};
  System.out.println("Values Before the sort:");
  for(i=0; i<array.length; i++)
    System.out.print(array[i]+" ");
    System.out.println();
    selection_srt(array, array.length);
    System.out.print("Values after the sort:\n");
    for(i=0; i<array.length; i++)
      System.out.print(array[i]+" ");
      System.out.println();
      System.out.println("End of the sort");
 }
 public static void selection_srt(int array[], int n)
 {
    for(int x=0; x<n; x++)
    {
      int index_of_min=x;
      for(int y=x; y<n; y++)
      {
        if(array[index_of_min]<array[y])
        {
          index_of_min=y;
        }
        int temp=array[x];
        array[x]=array[index_of_min];
        array[index_of_min]=temp;
      }
    }
    }
}

Activity:
Create a program that will interact with the user.

The program must do the following:
1. Ask the user "How many numbers will be sorted? "
2. Display the unsorted numbers.
3. Display the sorted numbers in ascending order.
4. Display the sorted numbers in descending order.
Back to top Go down
https://delmark.forumtl.com
 
Data Sorting: SelectionSort Java
Back to top 
Page 1 of 1
 Similar topics
-
» Data Sorting: BubbleSort Java
» Data Sorting: InsertionSort Java
» Java Comments
» Payroll Java
» Magic Square Java

Permissions in this forum:You cannot reply to topics in this forum
John Delmark Aguilar :: dElmARk Productions :: Java Programs :: Tutorials-
Jump to: