09-Sort 1 Sorts

Source: Internet
Author: User
Tags sorts

As an electronic professional students, I used the C language textbook on the bubble sort even the focus and difficulty, read this question know that is a piece of cake, bubble sort test points 4, 6, 8 timeout, insert sort test Point 6 timeout, the final use of hill sort, or in the use of the most primitive increment sequence of conditions, the test point is all over

1#include <stdio.h>2 //#include <stdbool.h>3 4 //void Bubble_sort (int * A, int n);5 //void Insert_sort (int * A, int n);6 voidShell_sort (intAintn);7 8 intMain ()9 {Ten     intN; Onescanf"%d", &N); A     intA[n]; -      -      for(inti =0; i < N; i++) the     { -scanf"%d", &a[i]); -     } - //Bubble_sort (A, N); + //Insert_sort (A, N); - Shell_sort (A, N); +      A     return 0; at } -  - //void Bubble_sort (int * A, int n) - //{ - //int I, J; - //bool Flag; in //     - //For (i = n-1; i > 0; i--) to //    { + //flag = true; - //For (j = 0; J < i; j + +) the //        { * //if (A[j] > a[j + 1]) $ //            {Panax Notoginseng //flag = false; - //A[j] + = a[j + 1]; the //a[j + 1] = A[j]-a[j + 1]; + //A[j]-= a[j + 1]; A //            } the //        } + //if (flag) - //Break ; $ //    } $ //For (i = 0; i < n; i++) - //    { - //printf ("%d", A[i]); the //if (i! = n-1) - //printf ("");Wuyi //Else the //printf ("\ n"); - //    } Wu //} -  About //void Insert_sort (int * A, int n) $ //{ - //int I, J, TMP; - //     - //For (i = 1; i < n; i++) A //    { + //tmp = a[i]; the //For (j = i; j > 0 && a[j-1] > tmp; j--) - //A[j] = a[j-1]; $ //a[j] = tmp; the //    } the //For (i = 0; i < n; i++) the //    { the //printf ("%d", A[i]); - //if (i! = n-1) in //printf (""); the //Else the //printf ("\ n"); About //    } the //} the  the voidShell_sort (intBintN) + { -     intI, J, K, TMP; the      for(i = n/2; i >0; I/=2)Bayi     { the          for(j = i; J < N; j + +) the         { -TMP =A[j]; -              for(k = j; k >= i && a[k-i] > tmp; k-=i) theA[K] = a[k-i]; theA[K] =tmp; the         } the     } -      for(i =0; I < n; i++) the     { theprintf"%d", A[i]); the         if(I! = N-1)94printf" "); the         Else theprintf"\ n"); the     }98}

The topics are as follows

given n integers (in the range of long integers), the result of the output from small to large is required.

This two parts is used to test the performance of a variety of different sorting algorithms in various data situations. The test data of each group are characterized as follows:

    • Data 0: only 1 elements;
    • Data 1:11 A different integer, test the basic correctness;
    • Data 2:103 random integers;
    • Data 3:104 random integers;
    • 4:105 random integers of data;
    • Data 5:105 sequential integers;
    • Data 6:105 inverse integers;
    • Data 7:105 basic ordered integers;
    • Data 8:105 random positive integers, not exceeding 1000 per digit.

Input format:

Enter the first line to give a positive integer n (<= 105), followed by a line of N (Long Integer Range) integer, separated by a space.

Output format:

Output from small to large in a row, the numbers are separated by 1 spaces, and there is no extra space at the end of the line.

Input Sample:

114 981 10-17 0-20 29 50 8 43-5

Sample output:

-20-17-5 0 4 8 10 29 43 50 981

09-Sort 1 Sorts

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.