个人认为今天学到的是status函数类型的意义:
#define TRUE 1
#define FALSE 0
#define OK 1
#define ERROR 0
#define INFEASIBLE -1
#define OVERFLOW -2
//说明Status函数的返回值是这六种类型的数
status函数类型需要我们自己定义:typedef int Status;定义完成
Status在抽象数据结构(D,S,P)中的P中运用;
知识预讲:函数类型&参数名,&是指引用参数,在C++中才出现的;
引用参数和普通传递进入函数的参数的不同是,引用参数不会引入副本。
即修改引用参数的值的时候就是修改传入参数的值,而传递参数会引入
一个副本即改变副本值的时候不会改变原始参数的值;
//--------------采用动态分配的顺序存储结结构------------------------------------------------------------//
typedef ElemType *Triplet;//D,(对象)。先要给InitTriplet分配三个元素的存储空间
//-------------------------------------------------------------------------------------------------------------------//
开始进入P(操作阶段)
//------------------------------------------------------------------------------------------------------------------//
Status InitTriplet(Triplet &T,ElemType v1,ElemType v2,ElemTpe v3);
//功能是在分配好的空间中赋值,则三元组(D,S,P)构建完成
//----------------------------------------------------------------------------------------------------------------//
Status Destroy(Triplet &T);//销毁三元组
//---------------------------------------------------------------------------------------------------------------//
Status Get(Triplet T,int i,Elemtype &e);//改变第i元的值为e;
//---------------------------------------------------------------------------------------------------------------//
。。。。。。
//---------------------------------------------------------------------------------------------------------------//
剩下的函数原型就不一一列举了,下面你是原型的实现:
//---------------------------------------------------------------------------------------------------------------//
Status InitTriplet(Triplet&T,ElemType v1,Elem Type v2,ElemType v3)
{
T=(ElemType *)malloc(3*sizeof(ElemType) );//T是指针变量初始值(全0)
if(!T) exit(OVERFLOW);分配空间失败(即地址值为00000000)
T[0]=v1;T[1]=v2;T[2]=v3;//对空间均分
return OK;
}//三元组构造完成;
//---------------------------------------------------------------------------------------------------------------//
剩下的函数实现我就不一一列举了,主要是在不同C语言语句的选择和应用上稍微注意即可
//---------------------------------------------------------------------------------------------------------------//
补充:&+参数
<span style="color: rgb(51, 51, 51); font-family: arial, 'courier new', courier, 宋体, monospace, 'Microsoft YaHei'; font-size: 14px; line-height: 24px; white-space: pre-wrap;">是引用,</span><a target=_blank data-id="link-to-so" data-c="点击实体词http%3A%2F%2Fwenda.haosou.com%2Fq%2F13817538130647401.0.0_1.0.1c++" text="点击实体词" target="_blank" href="http://www.haosou.com/s?q=c%2B%2B&ie=utf-8&src=wenda_link" style="margin: 0px; padding: 0px; color: rgb(135, 181, 243); text-decoration: none; cursor: pointer; font-family: arial, 'courier new', courier, 宋体, monospace, 'Microsoft YaHei'; font-size: 14px; line-height: 24px; white-space: pre-wrap;">c++</a><span style="color: rgb(51, 51, 51); font-family: arial, 'courier new', courier, 宋体, monospace, 'Microsoft YaHei'; font-size: 14px; line-height: 24px; white-space: pre-wrap;">中的概念,int a;int &b=a;这就声明了b是a的引用,经过这样的声明后使用a或b的作用相同,都代表同一变量。对变量声明一个引用,并不另开辟</span><a target=_blank data-id="link-to-so" data-c="点击实体词http%3A%2F%2Fwenda.haosou.com%2Fq%2F13817538130647401.0.0_1.0.1内存单元" text="点击实体词" target="_blank" href="http://www.haosou.com/s?q=%E5%86%85%E5%AD%98%E5%8D%95%E5%85%83&ie=utf-8&src=wenda_link" style="margin: 0px; padding: 0px; color: rgb(135, 181, 243); text-decoration: none; cursor: pointer; font-family: arial, 'courier new', courier, 宋体, monospace, 'Microsoft YaHei'; font-size: 14px; line-height: 24px; white-space: pre-wrap;">内存单元</a><span style="color: rgb(51, 51, 51); font-family: arial, 'courier new', courier, 宋体, monospace, 'Microsoft YaHei'; font-size: 14px; line-height: 24px; white-space: pre-wrap;">。函数</span><a target=_blank data-id="link-to-so" data-c="点击实体词http%3A%2F%2Fwenda.haosou.com%2Fq%2F13817538130647401.0.0_1.0.1参数传递" text="点击实体词" target="_blank" href="http://www.haosou.com/s?q=%E5%8F%82%E6%95%B0%E4%BC%A0%E9%80%92&ie=utf-8&src=wenda_link" style="margin: 0px; padding: 0px; color: rgb(135, 181, 243); text-decoration: none; cursor: pointer; font-family: arial, 'courier new', courier, 宋体, monospace, 'Microsoft YaHei'; font-size: 14px; line-height: 24px; white-space: pre-wrap;">参数传递</a><span style="color: rgb(51, 51, 51); font-family: arial, 'courier new', courier, 宋体, monospace, 'Microsoft YaHei'; font-size: 14px; line-height: 24px; white-space: pre-wrap;">有两种情况,有一般的将变量名作为参数,这时传递给形参的是变量的值,在执行函数的时候,形参的值发生的变化并不传递给实参。传递变量的指针,使形参得到一个变量的地址,这时形参</span><a target=_blank data-id="link-to-so" data-c="点击实体词http%3A%2F%2Fwenda.haosou.com%2Fq%2F13817538130647401.0.0_1.0.1指针变量" text="点击实体词" target="_blank" href="http://www.haosou.com/s?q=%E6%8C%87%E9%92%88%E5%8F%98%E9%87%8F&ie=utf-8&src=wenda_link" style="margin: 0px; padding: 0px; color: rgb(135, 181, 243); text-decoration: none; cursor: pointer; font-family: arial, 'courier new', courier, 宋体, monospace, 'Microsoft YaHei'; font-size: 14px; line-height: 24px; white-space: pre-wrap;">指针变量</a><span style="color: rgb(51, 51, 51); font-family: arial, 'courier new', courier, 宋体, monospace, 'Microsoft YaHei'; font-size: 14px; line-height: 24px; white-space: pre-wrap;">指向实参变量单元。引进引用后,函数参数的第三种传递方式就是传送变量的别名。 代替地址的传递,更加简单</span>
这是今天所学的主要内容