0
点赞
收藏
分享

微信扫一扫

Data Structures and Algorithms (English) - 6-9 Sort Three Distinct Keys(20 分)


题目链接:​​点击打开链接​​

题目大意:略。

解题思路:考查enum类型与int类型的转换,详情:​​C/C++ - enum 与 int 相互转换​​。

AC 代码

void MySort( ElementType A[], int N )
{
int fcnt, tcnt, mcnt;
fcnt=tcnt=mcnt=0;
for(int i=0;i<N;i++)
{
if(A[i]==false) fcnt++;
else if(A[i]==true) tcnt++;
else if(A[i]==maybe) mcnt++;
}
for(int i=0;i<fcnt;i++) A[i]=false;
for(int i=fcnt;i<fcnt+mcnt;i++) A[i]=maybe;
for(int i=fcnt+mcnt;i<N;i++) A[i]=true;
}


举报

相关推荐

0 条评论