Nothing Special   »   [go: up one dir, main page]

Java- direct sequencing method

tags: java  Direct sequencing  

aims

With the selected sorting method, in ascending order of the output element of the one-dimensional array.


Code

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]+" ");
		}
	}
	
	
	
	
	
	

}

Intelligent Recommendation

Several commonly used sequencing method implemented in Java

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...

[Java] [Component and Event Treatment] Sort by sequencing method

MyFrame: PoliceListen Main: This question is a bit of the taste of the file. The first step is to read each line of text domain 1 in a string number Numstrs [] (to change the behavior segmentation). S...

Direct insertion of the eight sequencing law

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

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 method (Java implementation)

Direct insertion Time complexity: o (N2) Space complexity: o (1) Stablize...

More Recommendation

Java basic learning - array (5, array sorting algorithm: bubble sort, direct sequencing, reverse sort)

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...

Branch and bound method | job sequencing with deadline | Java implementation

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...

Java one-dimensional number of group sequencing method must see

Select Sort is the first choice to have a smaller replacement without a smaller normal output. Welcome to...

One of the eight sorting algorithms: Direct sequencing

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...

Copyright  DMCA © 2018-2025 - All Rights Reserved - www.programmersought.com  User Notice

Top