堆排序中第一个元素没排序?#includeusing namespace std;#define MaxSize 100typedef int KeyType;typedef struct {KeyType key;}RecType;void sift(RecType R[],int low,int high){int i=low,j=2*i;RecType tmp=R[i];while(j

来源:学生作业帮助网 编辑:作业帮 时间:2024/05/01 10:54:33
堆排序中第一个元素没排序?#includeusing namespace std;#define MaxSize 100typedef int KeyType;typedef struct {KeyType key;}RecType;void sift(RecType R[],int low,int high){int i=low,j=2*i;RecType tmp=R[i];while(j

堆排序中第一个元素没排序?#includeusing namespace std;#define MaxSize 100typedef int KeyType;typedef struct {KeyType key;}RecType;void sift(RecType R[],int low,int high){int i=low,j=2*i;RecType tmp=R[i];while(j
堆排序中第一个元素没排序?
#include
using namespace std;
#define MaxSize 100
typedef int KeyType;
typedef struct
{
KeyType key;
}RecType;
void sift(RecType R[],int low,int high)
{
int i=low,j=2*i;
RecType tmp=R[i];
while(j

堆排序中第一个元素没排序?#includeusing namespace std;#define MaxSize 100typedef int KeyType;typedef struct {KeyType key;}RecType;void sift(RecType R[],int low,int high){int i=low,j=2*i;RecType tmp=R[i];while(j
主要原因是你的排序算法是从下标1开始,主函数中下标从0开始,改成一样的就可以了,下面是改过的主函数:
void main()
{
RecType R[MaxSize];
KeyType a[MaxSize];
cout