#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define N 10
//读取10个整型数据12 63 58 95 41 35 65 0 38 44,然后通过归并排序,对该组数据进行排序,输出有序结果,每个数的输出占3个空格
typedef int ElemType;
typedef struct{
ElemType *elem;//存储元素的起始地址
int TableLen;//元素个数
}SSTable;
//初始化
void ST_Init(SSTable &ST,int len)
{
ST.TableLen=len;
ST.elem=(ElemType *) malloc(sizeof (ElemType)*ST.TableLen);//申请空间,当数组使用
}
//打印元素
void ST_print(SSTable ST)
{
for (int i = 0; i < N; i++)
{
printf("%3d",ST.elem[i]);
}
printf("\n");
}
//合并数组
void Merge(ElemType *A,int low,int mid,int high)
{
static ElemType B[N];
int i,j,k;
for(i=low;i<=high;i++)
{
B[i]=A[i];//B用来比较
}
for(i=low,j=mid+1,k=i;i<=mid&&j<=high;k++)
{
if(B[i]>B[j])
A[k]=B[j+&#
王道c语言督学营课时17.2作业
最新推荐文章于 2024-07-25 23:26:35 发布