?? p229.cpp
字號:
#include "iostream.h" #include "p228.cpp" template <class Type> class searchList : public DataList<Type> { //搜索表searchList繼承了DataList, 并且增加了成員函數Search ( ) public: searchList ( int sz = 10 ) : DataList<Type> (sz) { } virtual ~searchList ( ) { } virtual int Search ( const Type & x ) const; int Search ( const Type & x, int loc ) const; }; template <class Type> int searchList<Type>::Search ( const Type & x ) const { //在搜索表searchList中順序搜索其關鍵碼為x的數據對象,要求數據對象在表中從下標1開始存放,第0號 //位置作為控制搜索過程自動結束的“監視哨”使用。若找到則函數返回該對象在表中的位置i,否則返回0。 Element[0].setKey ( x ); int i = CurrentSize; //將x送0號位置設置監視哨 while (Element[i].getKey ( ) != x ) i--; //從后向前順序搜索 return i; } template <class Type> int searchList<Type>::Search ( const Type & x, int loc ) const { if ( loc > CurrentSize ) return 0; else if ( Element[loc].getKey( ) == x ) return loc; else {return Search ( x, loc+1 );} }
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -