P34.CPP
上传用户:chaiyuqiu
上传日期:2022-08-03
资源大小:27k
文件大小:1k
源码类别:

数据结构

开发平台:

C/C++

  1. #include <datalist.h>
  2. #include <selecttm.h>
  3. template < class Type > void dataList <Type> :: BubbleSort() {
  4.     int i = 1;
  5.     int exchange = 1;
  6.     while ( i < ArraySize && exchange ) {
  7. BubbleExchange ( i, exchange );
  8. i++;
  9.     }
  10. }
  11. template < class Type > void dataList <Type> :: BubbleExchange ( const int i, int & exchange ) {
  12.     exchange = 0;
  13.     for ( int j = ArraySize - 1; j>=i; j-- )
  14.       if ( Element[j-1] > Element[j] ) {
  15.   Swap (j-1,j);
  16.   exchange = 1;
  17.       }
  18. }
  19. void main() {
  20.     dataList<int> abc;
  21. }