现在的位置: 首页 > 综合 > 正文

动态数组之八:搜索Find()应用

2013年08月26日 ⁄ 综合 ⁄ 共 503字 ⁄ 字号 评论关闭

//定义一个函数,按学号进行匹配
TBool MatchNum(const TStudent& aStu1, const TStudent& aStu2)
 {
 if (aStu1.iNum == aStu2.iNum)
  {
  return ETrue;
  }
 else EFalse;
 }

 //在TestArray()函数中添加的代码如下:
 TIdentityRelation<TStudent> matcher(MatchNum);
 TInt index = KErrNotFound; // 初始为没有找到匹配的数据
 index = stuRArray.Find(TStudent(_L("Green"),2,5),matcher);
 if (index != KErrNotFound)
  {
  console->Printf(KString1,&stuRArray[index].iName,stuRArray[index].iNum,stuRArray[index].iMark);
  }
 else
  {
  console->Printf(_L("None is found....."));
  }

  

运行的结果如图:找到学号为2的学生的数据

抱歉!评论已关闭.