Data structure tutorial The 37th experiment of Eight Order experiment

Source: Internet
Author: User
Tags printf sort

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&GT;=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 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.