JSP Insert Sort algorithm Instance code

Source: Internet
Author: User

public class Charusort {
public static void Main (string[] args) {

Int[] sort={4,6,3,9,5};

Sort (sort);

for (int i=0;i<sort.length;i++)

System.out.print (sort[i]+ "");

}

public static void sort (int[] sort) {

int i; Number of scans

Int J; As the element of comparison.

for (i=1;i<sort.length;i++) {//Scan count is sort.length-1

int temp; Temp for staging data

Temp=sort[i];

J=i-1;

while (J>=0&&temp<sort[j]) {//If the second element is less than the first element

SORT[J+1]=SORT[J]; Push all the elements back one position

j--;

}

Sort[j+1]=temp; The smallest element is placed in the first position

}

}

}

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.