bubsort.cpp

来自「数据结构与算法分析(C++)(版第二版)源码」· C++ 代码 · 共 22 行

CPP
22
字号
#include <iostream.h>
#include <stdlib.h>
#include <string.h>

#include "book.h"
#include "compare.h"

template <class Elem, class Comp>
void bubsort(Elem A[], int n) { // Bubble Sort
  for (int i=0; i<n-1; i++)     // Bubble up i'th record
    for (int j=n-1; j>i; j--)
      if (Comp::lt(A[j], A[j-1]))
        swap(A, j, j-1);
}

template <class Elem, class Comp>
void sort(Elem* array, int n) {
  bubsort<Elem,Comp>(array, n);
}

#include "sortmain.cpp"

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?