Java data structure Sorting insert sort realizes __ data structure

Source: Internet
Author: User
<span style= "FONT-SIZE:18PX;" >public class Insertsort {</span><pre name= "code" class= "Java" >public class Insertsort {static void print (int[] dataList)
		{for (int j = 0; J < Datalist.length; J + +) {System.out.print (datalist[j]+ "");
	} System.out.println ();
		} static void Insertsort (int[] dataList) {int flag,temp;
		System.out.print ("Original series is:");
		Print (dataList);
			for (int i = 1; i < datalist.length; i++) {flag=i;
			Temp=datalist[i];
				for (int j = i-1 J >= 0; j--) {if (Datalist[i]>=datalist[j]) {break;
				}else{flag=j;
			} System.out.println ("flag=" +flag+ "element to be inserted is:" +datalist[i]);			
				if (flag!=i) {for (int j = i-1 J >= Flag; j--) {datalist[j+1]=datalist[j];
			} Datalist[flag] = temp;
			} System.out.print ("+i+" The result of the trip order is: ");
		Print (dataList);
		} public static void Main (string[] args) {int[] dataList = {13,65,97,76,38,27,49,10};
	Insertsort (dataList); }
}


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.