算法导论-Introduction to Algorithms
算法导论-Introduction to Algorithms-Thomas H Cormen.Ronald.L.Rivest.Charles E Leiserson Clifford Stein
算法导论-Introduction to Algorithms-Thomas H Cormen.Ronald.L.Rivest.Charles E Leiserson Clifford Stein
如下: 5.10 -- 创建birthday 用户定义数据类型,它使用了 datetime 基本数据类型,允许 NULL USE sample EXEC sp_addtype birthday, datetime, 'NULL' GO -- 在数据表定义时使用birthday 用户定义数据类型 CREATE TABLE 特殊数据 ( char_data char(20), birthday_data birthday ) GO -- 向数据表中添加几条记录 INSERT INTO 特殊数据 VALUES ('Sarah', '02/22/1976') INSERT INTO 特殊数据 VALUES ('Tina', '04/15/1998') GO -- 从数据表中检索数据 SELECT * FROM 特殊数据 GO -- 删除birthday 用户定义数据类型 EXEC sp_droptype birthday
主函数调用三个函数void init(输入)、bool safe(安全性算法)、void bank(银行家算法).. 没有释放资源代码段 所以不能实现银行家算法的全部过程 定义如下 #include <iostream> using namespace std; #define MAXPROCESS 50 /*最大进程数*/ #define MAXRESOURCE 100 /*最大资源数*/ int AVAILABLE[MAXRESOURCE]; /*可用资源数组*/ int MAX[MAXPROCESS][MAXRESOURCE]; /*最大需求矩阵*/ int ALLOCATION[MAXPROCESS][MAXRESOURCE]; /*分配矩阵*/ int NEED[MAXPROCESS][MAXRESOURCE]; /*需求矩阵*/ int REQUEST[MAXPROCESS][MAXRESOURCE]; /*进程需要资源数*/ bool FINISH[MAXPROCESS]; /*系统是否有足够的资源分配*/ int p[MAXPROCESS]; /*记录序列*/ int m,n; /*m个进程,n个资源*/ void Init(); bool Safe(); void Bank();