• SDUT 3398 数据结构实验之排序一:一趟快排


    数据结构实验之排序一:一趟快排

    Time Limit: 1000MS Memory Limit: 65536KB

    Problem Description

    给定N个长整型范围内的整数,要求输出以给定数据中第一个数为枢轴进行一趟快速排序之后的结果。

     

    Input

    连续输入多组数据,每组输入数据第一行给出正整数N(N < = 10^5),随后给出N个长整型范围内的整数,数字间以空格分隔。

    Output

    输出一趟快速排序后的结果,数字间以一个空格间隔,行末不得有多余空格。

    Example Input

    8
    49 38 65 97 76 13 27 49

    Example Output

    27 38 13 49 76 97 65 49

    DQE:

    排序算法可参照快速排序-百度百科所给出的C++标准示例,去掉递归执行即为一趟快排。

     1 #include <iostream>
     2 #include <cstdio>
     3 using namespace std;
     4 int f[100010];
     5 
     6 void qs(int l,int r)
     7 {
     8     if(l>=r)
     9         return ;
    10     int k=f[l];
    11     int i=l,j=r;
    12     while(i<j)
    13     {
    14         while(i<j&&f[j]>=k)
    15             j--;
    16         f[i]=f[j];
    17         while(i<j&&f[i]<=k)
    18             i++;
    19         f[j]=f[i];
    20     }
    21     f[i]=k;
    22 //    qs(l,i-1);
    23 //    qs(i+1,r);
    24 }
    25 
    26 int main()
    27 {
    28     int n,i;
    29     while(scanf("%d",&n)!=EOF)
    30     {
    31         for(i=1;i<=n;i++)
    32             scanf("%d",f+i);
    33         qs(1,n);
    34         for(i=1;i<=n;i++)
    35             printf("%d%c",f[i],i==n?'
    ':' ');
    36     }
    37     return 0;
    38 }
    39 
    40 /***************************************************
    41 User name: ***
    42 Result: Accepted
    43 Take time: 0ms
    44 Take Memory: 168KB
    45 Submit time: 2016-12-03 13:44:08
    46 ****************************************************/
  • 相关阅读:
    深度学习中的Data Augmentation方法(转)基于keras
    caffe pytho接口
    finetuning caffe
    windows下配置Faster-RCNN
    caffe中的props
    centos上搭建git服务--3
    centos上搭建git服务--2
    Centos上搭建git服务
    loadrunner--基础2
    loadrunner11--基础使用
  • 原文地址:https://www.cnblogs.com/Leroscox/p/6128601.html
Copyright © 2020-2023  润新知