n维数组 0各维元素个数为m1,m2,m3y…,mn 0下标为i,i2,by…,i2的数组元素的存 储地址 LOC(,2,…,2)=i1米m2*m3*…求mn 1米m3、*m4米…菜mn+ +l km +i k k=j+1
n维数组 各维元素个数为 m1 , m2 , m3 , …, mn 下标为 i1 , i2 , i3 , …, in 的数组元素的存 储地址: n n j n k j j k n n n n n n i m i i m m m i m i LOC i i i i m m m + = + + + + = + − = = + − 1 1 1 2 3 4 1 1 2 1 2 3 ( , , , )
顺序表( Sequential lis 0顺序表的定义和特点 口定义n(≥0)个表项的有限序列 (a1,a2 9n a是表项,m是表长度 特点顺序存取 口遍历逐项访问 从前向后从后向前从两端向中间
顺序表 (Sequential List) 顺序表的定义和特点 定义 n( 0)个表项的有限序列 (a1 , a2 , …, an) ai是表项,n是表长度。 特点 顺序存取 遍历 逐项访问 从前向后 从后向前 从两端向中间
顺序表( Seg list类的定义 template <class Type> class seqlist i Type data /顺序表存储数组 int max size;最大允许长度 int lasts /当前最后元素下标 public: Seqlist int maxsize defaultsize ) Seqlist oi deletel data; int Length( const i return last+1;) int Find( type x)const;
顺序表(SeqList)类的定义 template <class Type> class SeqList { Type *data; //顺序表存储数组 int MaxSize; //最大允许长度 int last; //当前最后元素下标 public: SeqList ( int MaxSize = defaultSize ); ~SeqList ( ) { delete [ ] data; } int Length ( ) const { return last+1; } int Find ( Type & x ) const;
int IsIn( type &x) int Insert( Type &x, int i); int Remove( type &x); int Next( Type &x); int Prior( Type &x); int IsEmpty return last ==-1; 3 int IsFull return last ==MaxSize-1; 3 Type Get( int i)& returni<oi> last? NULL data[i];
int IsIn ( Type & x ); int Insert ( Type & x, int i ); int Remove ( Type & x ); int Next ( Type & x ) ; int Prior ( Type & x ) ; int IsEmpty ( ) { return last ==-1; } int IsFull ( ) { return last == MaxSize-1; } Type & Get ( int i ) { return i < 0 || i > last?NULL : data[i]; } }
顺序表部分公共操作的实现 template <class Type> Seq list<Type>:: Seq List( int sz)& 造函数 if(z>0){ Max size sz last=-1 data=new Type lMaxSizel
顺序表部分公共操作的实现 template <class Type> SeqList<Type>::SeqList ( int sz ) { //构造函数 if ( sz > 0 ) { MaxSize = sz; last = -1; data = new Type[MaxSize]; } }