C + + algorithm-Direct Insert sort

Source: Internet
Author: User

This small log, simple oh tidy up under the direct insertion sort, refer to eight sorting algorithms and degrees Niang direct insertion sort.

Eight of the sorting algorithm is better organized, here copy part of the explanation as their own records. Insert a record into the sorted ordered table to get a new, sequential table with a 1 increase in the number of records.

The source of the reference to the two articles, but in order to streamline the code to find the original code can also be optimized, the code of their own to organize the following:

    //time complexity is O (n^2)//space Complexity of O (1)//Direct Insert Sort: Inserts a record into a sorted ordered table to get a new, sequential table with a 1 increase in the number of recordstemplate< TypeName T >inlinevoidInsertsort (T a[],intN) {inti,j,t;  for(i =1;i< N; + +i) {t=A[i]; J= I1;  while(t<A[j]) {A[j+1]=A[j]; --J; } a[j+1] =T; }    }

C + + algorithm-Direct Insert 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.