• 快速排序--按姓名


    //按姓名快速排序

    #include <stdio.h>

    #include <string.h>

    #define N 10

    typedef struct student

    {

        int num;

        char name[20];

        char sex[2];

        int age;

    }stu[N];

    int quickpartition(struct student stu[],int low,int high)

    {

        struct student x;

        x=stu[low];

        while(low<high)

        {

            while((low<high)&&(strcmp(stu[high].name,x.name)<=0))

                high--;

            stu[low]=stu[high];

            while((low<high)&&(strcmp(stu[low].name,x.name)>=0))

                low++;

            stu[high]=stu[low];

        }

        stu[low]=x;

        return high;

    }

    void quicksort(struct student stud[],int low,int high)

    {

        int temp;

        if(low<high)

        {

            temp=quickpartition(stud,low,high);

            quicksort(stud,low,temp-1);

            quicksort(stud,temp+1,high);

        }

    }

    int main()

    {

        struct student stu1[4]={{1001,"zhang","m",19},

            {1002,"chen","f",20},

            {1003,"ma","m",20},

            {1004,"sun","m",18}};

        int len,i;

        len=sizeof(stu1)/sizeof(stu1[0]);

        quicksort(stu1,0,len-1);

        for(i=0;i<len;i++)

        {

            printf(" %d %s %s %d ",stu1[i].num,stu1[i].name,stu1[i].sex,stu1[i].age);

        }

        return 1;

    }

    运行结果:

  • 相关阅读:
    多维梯度下降
    梯度下降
    三种评价函数
    Gluon sgd
    Gluon.vision的几类数据集
    Gluon Data API
    Gluon 实现 dropout 丢弃法
    AlexNet 分类 FashionMNIST
    LeNet 分类 FashionMNIST
    LeNet
  • 原文地址:https://www.cnblogs.com/duanqibo/p/11119933.html
Copyright © 2020-2023  润新知