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

📄 快速排序1.txt

📁 数据结构学习用到的一些程序!!里面有二叉树相关的几个
💻 TXT
字号:
#include <dos.h>
#include <conio.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#define MAXSIZE 20 
typedef struct 
{
 int elemword[MAXSIZE]; 
 int count;
}SqList;
void InitialSqList(SqList&);
void QuickSort(SqList &); 
void QSort(SqList &,int,int); 
int Partition(SqList &,int,int); 
void PrintSqList(SqList); 
void main()
{
 SqList L; 
 char j='y'; 
 printf("本程序将演示快速排序的操作。\n");
 while(j!='n'&&j!='N')
 {
  InitialSqList(L); 
  QuickSort(L); 
  PrintSqList(L); 
  printf("继续进行下一次排序吗?(Y/N)");
  scanf(" %c",&j);
 }
 printf("程序运行结束!\n按任意键关闭窗口!\n");
 getchar();getchar();
}
void InitialSqList(SqList &L)
{
 int i;
 printf("请输入待排序的记录的个数:");
 scanf("%d",&L.count);
 printf("请输入待排序的记录的关键字(整型数):\n");
 for(i=1;i<=L.count;i++)
 scanf("%d",&L.elemword[i]);
}
void QuickSort(SqList &L)
{
 QSort(L,1,L.count);
}
void QSort(SqList &L,int low,int high)
{
 int pivotloc;
 if(low<high) 
 {
  pivotloc=Partition(L,low,high); 
  QSort(L,low,pivotloc-1); 
  QSort(L,pivotloc+1,high); 
 }
}
int Partition(SqList &L,int low,int high)
{
 int pivotkey; 
 pivotkey=L.elemword[low]; 
 while(low<high) 
 {
  while(low<high&&L.elemword[high]>=pivotkey)
   --high;
  L.elemword[low]=L.elemword[high];
  while(low<high&&L.elemword[low]<=pivotkey)
   ++low;
  L.elemword[high]=L.elemword[low]; 
 }
 L.elemword[low]=pivotkey;
 return low; 
}
void PrintSqList(SqList L)
{
 int i;
 printf("已排好序的序列如下:\n");
 for(i=1;i<=L.count;i++)
 printf("%4d",L.elemword[i]);
 printf("\n");
}

⌨️ 快捷键说明

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