51Testing软件测试论坛

 找回密码
 (注-册)加入51Testing

QQ登录

只需一步,快速开始

微信登录,快人一步

查看: 2430|回复: 2
打印 上一主题 下一主题

一个快速排序,有错误,应该怎么改啊,感谢指正

[复制链接]
  • TA的每日心情
    无聊
    前天 09:11
  • 签到天数: 406 天

    连续签到: 3 天

    [LV.9]测试副司令

    跳转到指定楼层
    1#
    发表于 2020-8-14 10:56:55 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
    1测试积点
    1. #include
    2. #include
    3. #include
    4. #define MAXSIZE 100

    5. typedef struct Student{
    6. char no[20];// 学号
    7. char name[20];// 姓名
    8. int price;// 成绩
    9. }Student;
    10. int sum=0;

    11. typedef struct{
    12. Student elem[MAXSIZE];//线性表占用的数组空间
    13. int last;//最后一个元素的下标
    14. }SeqList;

    15. //快速排序(学号)

    16. int Partition(SeqList &L,Student a[],int low,int high)
    17. {
    18. a[0]=a[low];
    19. int pivotkey=a[low].no;
    20. while(low {
    21. while(low=pivotkey) --high;
    22. a[low]=a[high];
    23. while(low<high&&a[low].no<=pivotkey) ++low;
    24. a[high]=a[low];
    25. }
    26. a[low]=a[0];
    27. return low;
    28. }

    29. void QSort(Student a[],int low,int high)
    30. {
    31. if(low<high){
    32. int pivotloc=Partition(L,a,low,high);
    33. QSort(L,a,low,pivotloc-1);
    34. QSort(L,a,pivotloc+1,high);
    35. }
    36. }
    37. void QuickSort(SeqList &L)
    38. {
    39. if(L.last<1)
    40. {
    41. printf("空表!");
    42. }
    43. Student a[MAXSIZE];//排序专用临时数组
    44. for(int i=1;i<=L.last;i++)
    45. a[i]=L.elem[i];
    46. QSort(L.elem,1,L.last);
    47. for(i=0;i<L.last;i++)
    48. {
    49. printf("学号:%s 姓名:%s 成绩:%d\n\n",L.elem[i].no,L.elem[i].name,L.elem[i].price);
    50. }
    51. printf("\n");
    52. }
    复制代码


    分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
    收藏收藏
    回复

    使用道具 举报

  • TA的每日心情
    奋斗
    2019-12-31 08:59
  • 签到天数: 975 天

    连续签到: 1 天

    [LV.10]测试总司令

    2#
    发表于 2020-8-17 08:33:50 | 只看该作者
    支持一下
    回复

    使用道具 举报

    本版积分规则

    关闭

    站长推荐上一条 /1 下一条

    小黑屋|手机版|Archiver|51Testing软件测试网 ( 沪ICP备05003035号 关于我们

    GMT+8, 2024-5-2 06:12 , Processed in 0.062665 second(s), 21 queries .

    Powered by Discuz! X3.2

    © 2001-2024 Comsenz Inc.

    快速回复 返回顶部 返回列表