⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sort.c

📁 C语言成绩管理系统
💻 C
字号:
#include "stdio.h"

/*==================Program Description=====================*/
/*  程序名称:select sort song.c                              */
/*  程序目的:使用选择排序法设计一个排序程序                 */
/*  Written by songfuyu                                      */
/*===========================================================*/
void SelectSort(int *list,int n)
{
   int i,j,k;
   int minIndex;
   int temp;
   for(i=0;i<n-1;i++)
   {

     minIndex=i;
     for(j=i+1;j<n;j++)
     {
       if(list[minIndex]>list[j])
       {
         minIndex=j;
        }
      }
      temp=list[i];
      list[i]=list[minIndex];
      list[minIndex]=temp;

      printf("\n Current sorting result:");
      for(k=0;k<n;k++)                                   
      {
        printf("%d  ",list[k]);
       }
    }
}
/*-------------------------------------------------------------*/
/*        主程序:输入数值数据,调用选项排序,打印排序结果        */
/*-------------------------------------------------------------*/
void main()
{
   int list[20];
   int i,index;
   int node;

   printf("\nPlease input the values you want to sort(Exit for 0):\n");

   index=0;

     /*****************读取数值存入数组****************/
     scanf("%d",&node);
     while(node!=0)
     {
        list[index]=node;
        index=index+1;
        scanf("%d",&node);
      }

      /************* 进行选择法排序***************/
      SelectSort(list,index);

      /**************打印最终结果****************/
      printf("\n\nFinal sorting resurt:  ");
      for(i=0;i<index;i++)
        {
           printf("%d ",list[i]);
         }
      getch();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -