Data Structure sorting and searching in C Language

Source: Internet
Author: User

Data Structure sorting and searching in C Language

Data structure experiment sorting 1: Fast sorting

Time Limit: 1000 MS Memory Limit: 65536KB

Submit Statistic

Problem Description

Given an integer in the range of N long integers, you must output the results after a fast sorting with the first number in the given data as the pivot.

Input

Continuous input of multiple groups of data, each group of input data is given in the first row of a positive integer N (N <= 10 ^ 5), followed by N integers in the Long Integer Range, numbers are separated by spaces.

Output

Output the result of a quick sorting. The numbers are separated by a space. No extra space is allowed at the end of the row.

Example Input

8

49 38 65 97 76 13 27 49

Example Output

27 38 13 49 76 97 65 49

#include 
 
  int s[100010];void struff(int s[], int l, int r){    int i, j, key;    i = l;    j = r;    key = s[i];    while(i < j)    {        while(i < j && s[j] >= key)            j--;        s[i] = s[j];        while(i < j && s[i] <= key)            i++;        s[j] = s[i];    }    s[i] = key;}int main(){    int t, i;    while(scanf("%d", &t) != EOF)    {        for(i = 0; i < t; i++)        {            scanf("%d", &s[i]);        }        struff(s, 0, t - 1);        for(i = 0; i < t; i++)        {            if(i == 0)                printf("%d", s[i]);            else                printf(" %d", s[i]);        }        printf("\n");    }    return 0;}
 

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.