#include<stdlib.h>
#include<stdio.h>
#include<iostream>
#define TRUE 1
#define FALSE 0
#define OK 1
#define ERROR 0
#define INFEASIBLE -1
typedef int status;
typedef int ElemType;
typedef ElemType* Triplet;
status InitTriplet(Triplet &T, ElemType v1, ElemType v2, ElemType v3)
{
T=(Triplet)malloc(3*sizeof(ElemType));
T[0]=v1;T[1]=v2;T[2]=v3;
return OK;
}
status DestoryTriplet(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 Max(Triplet T, ElemType &e)
{
e=((T[0]<=T[1]?T[1]:T[0])<=T[2]?T[2]:(T[0]<=T[1]?T[1]:T[0]));
return e;
}
status Min(Triplet T, ElemType &e)
{
e=((T[0]<=T[1]?T[0]:T[1])<=T[2]?(T[0]<=T[1]?T[0]:T[1]):T[2]);
return e;
}
void PrintTriplet(const Triplet T)
{
printf("%4d%4d%4d\n",T[0],T[1],T[2]);
}
int main()
{
Triplet T;
ElemType e;
InitTriplet(T,2,6,3);
PrintTriplet(T);
Get(T,2,e);
e=e*4;
put(T,1,e);
PrintTriplet(T);
if(IsAscending(T))
PrintTriplet(T);
else
printf("%4d\n",Min(T,e));
return 0;
}
|