#include <iostream>using namespace std; #define MAX_SIZE 100//maximum value for sorting arrays typedef struct {int r[max_size+1] ;//used to store the array to sort int length;//for the length of the Record order table}sqlist;//the value of the array element for the interchange array R subscript I and subscript j void Swap (sqlist* L, int i,int j) {int temp;temp= l->r[i]; l->r[i]=l->r[j]; L->r[j]=temp;} Insert sort here the array is starting from 1, subscript 0 No value/* Assume that the front is ordered, and then insert the following elements in front, so that the front is always ordered */void Insert_sort (sqlist* L) {int len=l-> length;//array length int key;//intermediate value for (int i=2;i!=len;i++)//start loop from second element {if (l->r[i]<l->r[i-1])/{key=l->r[i]; int J=i-1;while (J>=1&&KEY<L->R[J])//moves the preceding array element backward {l->r[j+1]=l->r[j];//Moves the previous array element back in turn j-- ;//}l->r[j+1]=key;//inserts a value into}}}int main () {sqlist L; l.length=3; l.r[1]=3; l.r[2]=2; l.r[3]=4;for (int i=1;i<=3;i++) cout<<l.r[i]<<endl;insert_sort (&l); for (int i=1;i<=3;i++) cout <<l.r[i]<<endl;system ("pause"); return 1;}
Big talk data structure--insert sort