建立抽象数据类型 三元组

来源:百度知道 编辑:UC知道 时间:2024/09/23 09:33:15
#define TRUE 1
#define FALSE 0
#define OK 1
#define ERROR 0
#define INFEASIBLE -1
#define OVERFLOW -2
#include "malloc.h"
#include "stdio.h"
typedef int ElemTtpe
typedef int Status/*说明语法错误,为什么?*/
typedef ElemType *Triplet
main()
{

Status initTriplet(Triplet &T,ElemType v1,ElemType v2,ElemType v3)
{

T=(ElemType *)malloc(3 * sizeof (ElemType));
if(!T)
exit(OVERFLOW);
T[0]=v1;T[1]=v2;T[2]=v3;
return OK;
}
}

你那3句typedef连分号都不写,当然不对咯。。

#include <stdio.h>
#include <malloc.h>
#include <process.h>
#define OK 1
#define ERROR 0
#define OVERFLOW -2
typedef int Status;
typedef int ElemType;
typedef ElemType *Triplet;
Status InitTriplet(Triplet &T,ElemType v1,ElemType v2,ElemType v3)
{
T=(ElemType*)malloc(3 *sizeof(ElemType));
if(!T) exit (OVERFLOW);
T[0]=v1,T[1]=v2,T[2]=v3;
return OK;

}
Status DestroyTriplet(Triplet &T)
{
free(T); T=NULL;
return OK;
}

Status Get(Triplet T,int i,ElemType e)
{
if(i<1||i>3) return ERROR;
e=T[i-1];
return OK;
}
Status Put(Triplet T,int i,ElemType e)
{
if(i<1||i>3) return ERROR;
T[i-1]=e;
return OK;
}
Status IsAscending(Triplet T)
{
return (T[0]<=T[1]&&T[1]<=T[2]);
}
Status IsDescending(Triplet T)
{
return (T[0