tags: java Direct sequencing
With the selected sorting method, in ascending order of the output element of the one-dimensional array.
import com.sun.org.apache.bcel.internal.generic.Select;
public class SelectSort {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int num [] = new int [] {4,23,6,2,87,45,32,1}; // declare an array
SelectSort ss = new SelectSort();
ss.arraySort(num);
System.out.println("-------------------");
ss.sort(num);
}
/*
* Output original array elements
*/
public void arraySort(int num[])
{
System.out.println ( "the original array:");
for(int i=0; i<num.length; i++)
{
System.out.println(num[i]+" ");
}
}
/*
* Direct sequencing method
*/
public void sort(int num[])
{
int t = 0;
for(int i=0; i<num.length; i++)
{
for(int j = i+1; j<num.length; j++)
{
if(num[i] > num[j])
{
t = num[i];
num[i] = num[j];
num[j] = t;
}
}
}
// output array after sorting
System.out.println ( "directly after the sorted array:");
for(int i=0; i<num.length; i++)
{
System.out.println(num[i]+" ");
}
}
}
Several commonly used sequencing method implemented in Java Ado, directly on the code If there are errors, welcome to leave a message! ! ! my personal microblogging: do not knock code white, welcome a...
This article 1. Basic ideas The elements to be inserted are inserted from the sequence that has been ranked forward. (1) Set the element to TEMP to be inserted (2) Compare it with the previous element...
Link table implementation direct sequencing Think First disconnect the head knot from the subsequent node, point to the next first node with the position pointer. At this time, the subsequent node is ...
Direct insertion Time complexity: o (N2) Space complexity: o (1) Stablize...
5, array sorting algorithm 1, bubble sort Basic ideas: Basic ideas of bubbling are compared to adjacent element values, if they exchange element values, move smaller elements to the array, move the la...
Write in front Welcome to discuss~ Problem Description Jobs are allowed to have different processing times, and each job i is associated with a triple (pi, di, ti). Goal: A sub-set J of n jobs, jobs i...
Select Sort is the first choice to have a smaller replacement without a smaller normal output. Welcome to...
Direct sequencing Generally, insertion sort are implemented using in-place on the array. The algorithm is described as follows: From the beginning of the first element, the element can be considered t...
...