Big talk data structure--bubble sort

Source: Internet
Author: User
#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

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.