#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;} Bubble sort (compare SB's) int maopaopaixu_sb (sqlist* L) {int len=l->length;for (int i=1;i!=len;++i) {for (int j=i+1;j!=len;++j) { if (L->r[i]>l->r[j]) swap (L,I,J);}} return 1;} Bubble sort (normal) int maopaopaixu_zc (sqlist* L) {int len=l->length;for (int i=1;i!=len;++i) {for (int j=len;j!=i;j--) {if (L- >R[J]<L->R[J-1]) swap (l,j,j-1);}} return 1;} Bubble sort (optimization) int maopaopaixu_yh (sqlist* L) {int len=l->length;int flag=0;for (int i=1;i!=len;++i) {flag=0;for (int j=len ; j!=i;j--) {if (l->r[j]<l->r[j-1]) {swap (l,j,j-1); flag=1;}} if (flag==0) break;} return 1;} int main () {}
Big talk data structure--bubble sort