Algorithmic Learning: inserting sort

Source: Internet
Author: User
The insertion sort is suitable for smaller data volumes, and the higher the degree of sorting, the higher the efficiency, but the less efficient the amount of data that is made up of random numbers. The simple code is as follows #include <stdio.h> void quicksort (int array[],int Last)//ascending order, direct row {int i,j;int temp=0;for (i=1;i<last;i++)//starting from second bit, first bit default {temp=array[i];j=i-1;// The number moves back while ((j>=0) && (array[j]>temp)) {array[j+1]=array[j];//, from the end to the front end///compared to the sorted number, when the last one to be sorted is greater than temp. Move the previous one j--;} There is a number if (j!=i-1) {array[j+1]=temp;};} that is greater than temp; for (i=0;i<last;i++) {printf ("%d", Array[i]);}} void Quicksort (int*array,int N)//directly modified with pointers, with the same contents as above {inti,j;int temp;for (i=1;i<n;i++) {temp=* (array+i); for (j=i;j >0&&* (array+j-1) >temp;j--) {* (array+j) =* (array+j-1);} * (ARRAY+J) =temp;}}   void Main () {int a[1000]={0},n,i;   scanf ("%d", &n);   for (i=0;i<n;i++) scanf ("%d", &a[i]);   Quicksort (A,n); If you use the pointer to modify, you need to use this sentence: for (i=0;i<n;i++) printf ("%d", A[i]);}

Algorithmic Learning: inserting sort

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.