0001 /****************************************************************************************** 0002 * Data Structures in C++ 0003 * ISBN: 7-302-33064-6 & 7-302-33065-3 & 7-302-29652-2 & 7-302-26883-3 0004 * Junhui DENG, deng@tsinghua.edu.cn 0005 * Computer Science & Technology, Tsinghua University 0006 * Copyright (c) 2006-2013. All rights reserved. 0007 ******************************************************************************************/ 0008 0009 template <typename T> //向量的起泡排序(基本版) 0010 void Vector<T>::bubbleSort( Rank lo, Rank hi ) { //assert: 0 <= lo < hi <= size 0011 while( lo < --hi ) { //反复起泡扫描 0012 for( Rank i = lo; i < hi; i++ ) //逐个检查相邻元素 0013 if( _elem[i] > _elem[i + 1] ) //若逆序,则 0014 swap( _elem[i], _elem[i + 1] ); //经交换使局部有序 0015 } 0016 }