?? p229.cpp
字號:
#include "iostream.h"
#include "p228.cpp"
template <class Type> class searchList : public DataList<Type> {
//搜索表searchList繼承了DataList, 并且增加了成員函數(shù)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中順序搜索其關(guān)鍵碼為x的數(shù)據(jù)對象,要求數(shù)據(jù)對象在表中從下標(biāo)1開始存放,第0號
//位置作為控制搜索過程自動結(jié)束的“監(jiān)視哨”使用。若找到則函數(shù)返回該對象在表中的位置i,否則返回0。
Element[0].setKey ( x ); int i = CurrentSize; //將x送0號位置設(shè)置監(jiān)視哨
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 );}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -