DATA SIRUCTURES Add (x, y): NaturalNumber: if (c+y<=MaxInt 返回x+ else返回 Maxent Equal(x, y): Boolean f(x=y)返回Tru e else 返回F alse Successor(c): NaturalNumber if(x=-Maclnt) 返回x eise 返回x+1 Subtract(x,y): VaturalNumber if(x<y)返回0 eise 返回x-y end NaturalNumber Department of Computer Science Technology, Nanjing University fall
Department of Computer Science & Technology, Nanjing University fall DATA STRUCTURES Add (x, y) : NaturalNumber: if (x+y<=MaxInt) 返回 x+y else 返回MaxInt Equal (x, y) :Boolean if (x==y) 返回True else 返回 False Successor (x) : NaturalNumber if (x==MaxInt) 返回 x else 返回 x+1 Subtract (x, y) :NaturalNumber`if (x < y) 返回 0 else 返回 x - y end NaturalNumber
DATA SIRUCTURES 1.3模板 定义 适合多种数据类型的类定义或算法, 在特定环境下通过简单地代换,变成针 对具体某种数据类型的类定义或算法 Department of Computer Science Technology, Nanjing University fall
Department of Computer Science & Technology, Nanjing University fall DATA STRUCTURES 定义 适合多种数据类型的类定义或算法, 在特定环境下通过简单地代换,变成针 对具体某种数据类型的类定义或算法 1.3 模板
DATA SIRUCTURES 用模板定义用于排序的数据表( datalist类 #ifndef datalist h #define datalist h #include <iostream.h> template <class Type> class dataList t private Type“ Element; int Array Size void Swap(const int ml, const int m2); int MaxKey( const int low, const int high Department of Computer Science Technology, Nanjing University fall
Department of Computer Science & Technology, Nanjing University fall DATA STRUCTURES 用模板定义用于排序的数据表(dataList)类 #ifndef DATALIST_H #define DATALIST_H #include <iostream.h> template <class Type> class dataList { private: Type *Element; int ArraySize; void Swap (const int m1, const int m2); int MaxKey (const int low, const int high);