写了一个三元组,但是不知道哪里出错了,,,求助!
写了一个三元组,但是不知道哪里出错了,,,求助!头文件:
#ifndef H
#define H
#define TURE 1
#define FLASE 0
#define OK 1
#define ERROR 0
#define INFEASIBLE -1
#define OVERFLOW -2
typedef int Status;
typedef ElemType;
typedef ElemType *Triplet;
Status InitTriplet(Triplet &T,ElemType v1,ElemType v2,ElemType v3);
Status DestroyTriplet(Triplet &T);
Status Get(Triplet,int i,ElemType &e);
Status Put(Triplet&T,int i,ElemType e);
Status IsAscending (Triplet T);
Status IsDescending (Triplet T);
Status Max (Triplet T,ElemType &e);
Status Min (Triplet T,ElemType &e);
#endif
Source Fils:
#include "stdio.h"
#include "stdlib.h"
#include "1.h"
void main ()
{
ElemType v1,v2,v3,e,a,b,c;
Triplet T;
scanf("%d,%d,%d",&a,&b,&c);
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]>=T[1]&&T[1]>=T[2]);
}
Status Min(Triplet T,ElemType &e)
{
e=(T[0]<=T[1])?((T[0]<=T[2])?T[0]:T[2]):((T[1]>=T[2])?T[1]:T[2]);
return OK;
}
Status Max(Triplet T,ElemType &e)
{
e=(T[0]>=T[1])?((T[0]>=T[2])?T[0]:T[2]):((T[1]>=T[2])?T[1]:T[2]);
return OK;
}
}