p34.cpp

来自「经典的c++版数据结构教程」· C++ 代码 · 共 24 行

CPP
24
字号
#include <datalist.h>
#include <selecttm.h>

template < class Type > void dataList <Type> :: BubbleSort() {
    int i = 1;
    int exchange = 1;
    while ( i < ArraySize && exchange ) {
	BubbleExchange ( i, exchange );
	i++;
    }
}

template < class Type > void dataList <Type> :: BubbleExchange ( const int i, int & exchange ) {
    exchange = 0;
    for ( int j = ArraySize - 1; j>=i; j-- )
      if ( Element[j-1] > Element[j] ) {
	  Swap (j-1,j);
	  exchange = 1;
      }
}

void main() {
    dataList<int> abc;
}

⌨️ 快捷键说明

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