Home > Back-end >  Data structure, the result is wrong, bosses to help solve it
Data structure, the result is wrong, bosses to help solve it

Time:10-09

# include & lt; stdio.h>
# define OK 1
# define the ERROR 0
Typedef int the Status;
//triple type is defined as the first float, can change into other types of
Typedef float ElemType;
Typedef struct
{
ElemType e [3].
} Triplet.
The Status initTriplet (Triplet & amp; T, ElemType where V0, ElemType ElemType V1, V2)
{
T.e [0]=where V0;
T.e [1]=V1;
T.e [2]=V2;
Return OK;
}
The Status destroyTriplet (Triplet & amp; T)
{
Return OK;
}
The Status getElem (Triplet T, int I, ElemType & amp; E)
{
If (i<1 | | i> 3)
Return the ERROR;
The else
E=T.e [I - 1);
Return e;
}
The Status putElem (Triplet & amp; T, int I ElemType e)//
{
If (i<1 | | i> 3)
Return the ERROR;
The else
T.e] [I - 1=e;
Return e;
}
The Status isAscending (Triplet T)
{
Return (T.e [0] <=T.e [1]) & amp; & (T.e [1] <=T.e [2]);
}
The Status isDescending (Triplet T)
{
Return (T.e [0] & gt;=T.e [1]) & amp; & (T.e [1] & gt;=T.e [2]);
}
ElemType getMax (Triplet T, ElemType & amp; E)
{
If (T.e [0] & gt; T.e [1])
E=T.e [0].
The else
E=T.e [1].
If (T.e [2] & gt; E)
E=T.e [2].
Return e;
}
ElemType getMin (Triplet T, ElemType & amp; E)
{
If (T.e [0] E=T.e [0].
The else
E=T.e [1].
If (T.e [2] E=T.e [2].
Return e;
}
Int main ()
{
Triplet T;
The Status flag.
ElemType where v0, v1, v2, e;
Printf (" please enter the triad of three values where v0, v1, v2: \ n ");
The scanf (" % f, % f, % f ", & amp; Where v0, & amp; V1, & amp; V2);
Flag=initTriplet (T, where v0, v1, v2);
Printf (" call after initialization function, flag=% d, the three value of T % 4.2 f, % 4.2 f, % 4.2 f \ n ", flag, T.e [0], T.e [1], T.e [2]).
If (isAscending (T))
Printf (" the triad elements for ascending \ n ");
If (isDescending (T))
Printf (" the triad elements for descending \ n ");
Printf (" the maximum of the triad elements to: % 4.2 f, minimum value is: % 4.2 f ", getMax (T, e), getMin (T, e));
Return OK;
}
















CodePudding user response:

 # include & lt; stdio.h> 

# define OK 1
# define the ERROR 0

Typedef int the Status;
//triple type is defined as the first float, can change into other types of
Typedef float ElemType;

Typedef struct
{
ElemType e [3].
} Triplet.

The Status initTriplet (Triplet & amp; T, ElemType where V0, ElemType ElemType V1, V2)
{
T.e [0]=where V0;
T.e [1]=V1;
T.e [2]=V2;
Return OK;
}

The Status destroyTriplet (Triplet & amp; T)
{
Return OK;
}

The Status getElem (Triplet T, int I, ElemType & amp; E)
{
If (i<1 | | i> 3)
Return the ERROR;
The else
E=T.e [I - 1);
//return e;
Return OK;//should be here is to return OK
}

The Status putElem (Triplet & amp; T, int I ElemType e)//
{
If (i<1 | | i> 3)
Return the ERROR;
The else
T.e] [I - 1=e;
//return e;
Return OK;
}

The Status isAscending (Triplet T)
{
Return (T.e [0] <=T.e [1]) & amp; & (T.e [1] <=T.e [2]);
}

The Status isDescending (Triplet T)
{
Return (T.e [0] & gt;=T.e [1]) & amp; & (T.e [1] & gt;=T.e [2]);
}

ElemType getMax (Triplet T, ElemType & amp; E)
{
If (T.e [0] & gt; T.e [1])
E=T.e [0].
The else
E=T.e [1].
If (T.e [2] & gt; E)
E=T.e [2].

Return e;
}

ElemType getMin (Triplet T, ElemType & amp; E)
{
If (T.e [0] E=T.e [0].
The else
E=T.e [1].

If (T.e [2] E=T.e [2].
Return e;
}

Int main ()
{
Triplet T;
The Status flag.
ElemType where v0, v1, v2, e;
Printf (" please enter the triad of three values where v0, v1, v2: \ n ");
The scanf (" % f, % f, % f ", & amp; Where v0, & amp; V1, & amp; V2);
Flag=initTriplet (T, where v0, v1, v2);
Printf (" call after initialization function, flag=% d, the three value of T % 4.2 f, % 4.2 f, % 4.2 f \ n ", flag, T.e [0], T.e [1], T.e [2]).
If (isAscending (T))
Printf (" the triad elements for ascending \ n ");
If (isDescending (T))
Printf (" the triad elements for descending \ n ");
Printf (" the maximum of the triad elements to: % 4.2 f, minimum value is: % 4.2 f \ n ", getMax (T, e), getMin (T, e));
Return OK;
}




For your reference ~

Note the need when input use commas,

CodePudding user response:

Thank you, forgot to lose a comma
  • Related