Java implementation of several simple sort __java

Source: Internet
Author: User
Tags sorts
Java's simple sort includes: Insert sort, select sort, bubble sort, order sort. Now paste its code as follows:
public class Arrays {public static void main (string[] args) {int a[]=new int[]{7,6,5,4,3,2,1};//Insertsort (a);//
		Bubblesort (a);
		Selectedsort (a);
	Print (a);
		public static void print (int a[]) {for (int i=0;i<a.length;i++) {System.out.print (a[i]+ "");
	} System.out.println ();
				public static void Bubblesort (int a[]) {//bubble sort for (int i=0;i<a.length-1;i++) {for (int j=i+1;j<a.length;j++) {
					if (A[i]>a[j]) {int temp=a[i];
					A[I]=A[J];
				A[j]=temp;
			}}} public static void Selectedsort (int a[]) {//select sort for (int i=0;i<a.length-1;i++) {//up to a.length-1 trip sort
			int min=i;
				for (int j=i+1;j<a.length;j++) {if (A[j]<a[min]) {min=j;
			} int temp=a[min];
			A[min]=a[i];
		A[i]=temp;
		The public static void Insertsort (int a[]) {//Insert sort, can only take the overridden method int i,j;
			for (i=1;i<a.length;i++) {int temp=a[i];
				for (j=i;j>0;j--) {if (a[j-1]>temp) {a[j]=a[j-1];
		}} a[j]=temp;
 }
		
	}
}
<span style= "Font-family:arial;background-color:rgb (255, 255, 255);" > Simple comparison of several sorts of:</span>
<span style= "Font-family:arial;background-color:rgb (255, 255, 255);" > Insert Sort: Generally, the most efficient;</span> in these sorts of categories
<span style= "Font-family:arial;background-color:rgb (255, 255, 255);" > select sort: Reduces the number of exchanges relative to bubble sort;</span>
<span style= "Font-family:arial;background-color:rgb (255, 255, 255);" > Bubble Sort: simplest, but relatively inefficient </span>
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.