Teaching Objective: To master the algorithm of simple insertion, fast sorting, heap sorting and its application.
Teaching Focus:
Teaching Difficulties:
Teaching Content:
Implement the following three algorithms and validate them with the following unordered sequence:
49,38,65,97,76,13,27,49
First, simple insertion sort
Second, fast sorting
Third, heap sorting
The above algorithm C source program.
#define MAXSIZE #define LT (A,b) ((a) < (b)) typedef int KEYTYPE;
typedef int INFOTYPE;
typedef struct{KEYTYPE Key;
InfoType Otherinfo;
}redtype;
typedef struct{Redtype R[maxsize+1];
int length;
}sqlist;
void Insertsort (SqList *l) {int i,j;
for (i=2;i<=l->length;++i) if (LT (L->r[i].key,l->r[i-1].key)) {l->r[0]=l->r[i]; for (j=i-1; LT (L->r[0].key,l->r[j].key);
--J) l->r[j+1]=l->r[j];
l->r[j+1]=l->r[0];
} void Binsertsort (SqList *l) {int i,j;
int low,high,m;
for (i=2;i<=l->length;++i) {l->r[0]=l->r[i];
Low=1;high=i-1;
while (Low<=high) {m= (Low+high)/2;
if (LT (L->r[0].key,l->r[m].key)) high=m-1;
else low=m+1;
for (J=I-1;J>=HIGH+1;--J) l->r[j+1]=l->r[j];
l->r[high+1]=l->r[0];
}/* QuickSort related function */int Partition (sqlist *l,int high) {int low,int;
l->r[0]=l->r[low]; pivotkey=l->r[Low].key;
while (Low