include<stdio.h>
#include<stdlib.h>
#define OK 1
#define ERROR 0
#define TRUE 1
#define FLASE 0
#define OVERFLOW -2
typedef int Status;
typedef int *Triplet;
Status InitTrilplet(Triplet &T,int v1,int v2,int v3)
//构造一个三元数组T,依次置T的3个元素初值为v1,v2,v3
{
T=(int *)malloc(3*sizeof(int));
if(!T) exit(OVERFLOW);
T[0]=v1;T[1]=v2;T[2]=v3;
return OK;
}
Status Get(Triplet T,int i,int &e)
//1<=i<=3,用e返回T的第i元的值
{
if(i<1||i>3) return ERROR;
e=T[i-1];
return OK;
}
Status Put(Triplet &T,int i,int e)
//1<=i<=3,用e返回T的第i元的值
{
if(i<1||i>3) return ERROR;
e=T[i-1];
return OK;
}
Status IsAscending(Triplet T)
//如果T的3个元素按升序排列,则返回1
{
if(T[0]<T[1]&&T[1]<T[2])
return OK;
else
return ERROR;
}
int main()
{
Triplet T;
int e;
int v1,v2,v3;
v1=8;v2=4;v3=5;
InitTrilplet( T, v1, v2, v3);
printf("%d %d %d\n",T[0],T[1],T[2]);
Get( T, 1,e);
printf("%d\n",e);
int p=11;
Put(T,2,p);
Get( T, 2,e);
printf("%d\n",e);
if(IsAscending( T)) printf("YES\n");
else printf("NO\n");
return OK;
}
#include<stdlib.h>
#define OK 1
#define ERROR 0
#define TRUE 1
#define FLASE 0
#define OVERFLOW -2
typedef int Status;
typedef int *Triplet;
Status InitTrilplet(Triplet &T,int v1,int v2,int v3)
//构造一个三元数组T,依次置T的3个元素初值为v1,v2,v3
{
T=(int *)malloc(3*sizeof(int));
if(!T) exit(OVERFLOW);
T[0]=v1;T[1]=v2;T[2]=v3;
return OK;
}
Status Get(Triplet T,int i,int &e)
//1<=i<=3,用e返回T的第i元的值
{
if(i<1||i>3) return ERROR;
e=T[i-1];
return OK;
}
Status Put(Triplet &T,int i,int e)
//1<=i<=3,用e返回T的第i元的值
{
if(i<1||i>3) return ERROR;
e=T[i-1];
return OK;
}
Status IsAscending(Triplet T)
//如果T的3个元素按升序排列,则返回1
{
if(T[0]<T[1]&&T[1]<T[2])
return OK;
else
return ERROR;
}
int main()
{
Triplet T;
int e;
int v1,v2,v3;
v1=8;v2=4;v3=5;
InitTrilplet( T, v1, v2, v3);
printf("%d %d %d\n",T[0],T[1],T[2]);
Get( T, 1,e);
printf("%d\n",e);
int p=11;
Put(T,2,p);
Get( T, 2,e);
printf("%d\n",e);
if(IsAscending( T)) printf("YES\n");
else printf("NO\n");
return OK;
}