6-2 sdut-C语言实验-递归函数之快速排序

简介: 6-2 sdut-C语言实验-递归函数之快速排序

6-2 sdut-C语言实验-递归函数之快速排序

分数 12

全屏浏览

切换布局

作者 maggie

单位 山东理工大学

本题要求实现一个快速排序函数。

给定 N ( N<= 100000) 个 int 范围内的整数,要求用快速排序对数据进行升序排列。

函数接口定义:

void Quick_sort (int array[], int l, int r);


其中 array[] 、 l 、r 都是用户传入的参数。 array[] 是需要排序的数组,数组长度不会超过100000; l 和 r 是需要进行排序的左端点和右端点。


裁判测试程序样例:

#include <stdio.h> void Quick_sort (int array[], int l, int r); int main() { int N, array[100000]; scanf("%d", &N); for(int i=0; i<N; i++) { scanf("%d", &array[i]); } Quick_sort(array, 0, N-1); for(int i=0; i<N; i++) { printf("%d ", array[i]); } printf("\n"); return 0; } /* 你的代码将被嵌在这里 */


输入样例:

1. 8
2. 49 38 65 97 76 13 27 49

输出样例:

在这里给出相应的输出。例如:

13 27 38 49 49 65 76 97


代码长度限制

16 KB

时间限制

400 ms

内存限制

64 MB

struct NODE *creat_node(int n)
{
    struct NODE *tail,*p,*head;
    head=(struct NODE*)malloc(sizeof(struct NODE));
    head->next=NULL;
    tail=head;
    for(int i=0;i<n;i++)
    {
        p=(struct NODE*)malloc(sizeof(struct NODE));
        scanf("%d",&p->data);
        p->next=NULL;
        tail->next=p;
        tail=tail->next;
        
    }
    return head;
}
void printf_node(struct NODE *head)
{
    struct NODE*q;
    q=head->next;
    while(q)
    {
        if(q->next==NULL)
        {
            printf("%d\n",q->data);
        }
        else{
            printf("%d ",q->data);
        }
        q=q->next;\\max
    }
}
目录
相关文章
|
3月前
7-2 sdut-C语言实验-删数问题(贪心法二)
7-2 sdut-C语言实验-删数问题(贪心法二)
25 2
|
3月前
|
BI
7-7 sdut-C语言实验-上升子序列
7-7 sdut-C语言实验-上升子序列
20 0
|
3月前
6-1 sdut-C语言实验-递归函数之快速排序
6-1 sdut-C语言实验-递归函数之快速排序
16 1
|
3月前
7-1 sdut-C语言实验-递归的函数
7-1 sdut-C语言实验-递归的函数
20 2
|
3月前
7-4 sdut-C语言实验-区间覆盖问题
7-4 sdut-C语言实验-区间覆盖问题
24 2
|
3月前
7-10 sdut-C语言实验-走迷宫
7-10 sdut-C语言实验-走迷宫
19 2
|
3月前
|
算法
7-2 sdut-C语言实验-数字三角形问题
7-2 sdut-C语言实验-数字三角形问题
15 1
|
3月前
6-1 sdut-C语言实验-快速排序
6-1 sdut-C语言实验-快速排序
14 0
|
3月前
6-2 sdut-C语言实验-二分查找
6-2 sdut-C语言实验-二分查找
27 0
|
3月前
7-3 sdut-C语言实验-简单递归函数
7-3 sdut-C语言实验-简单递归函数
21 0