struct+vector实现树结构

typedef struct tagGateInfo
{
 char GateName[20];
 int  GateValue;
}GateInfo;

typedef struct tagBeamInfo
{
 char BeamName[20];
 int BeamValue;
 vector<tagGateInfo> vGateInfo;

}BeamInfo;

typedef struct tagChannelInfo
{
 char ChannelName[20];
 int ChannelValue;
 vector<tagBeamInfo> vBeamInfo;
}ChannelInfo;

typedef struct tagDataInfo
{
 char DataName[20];
 int DataValue;
 vector<tagChannelInfo> vChannelInfo;
}DataInfo;

 

 

VectorTest::GetVector(tagDataInfo &stuDataInfo)
{
 CString strMsg = NULL;

 strMsg.Format("DataName%");
 strncpy(stuDataInfo.DataName,strMsg,strMsg.GetLength());
 stuDataInfo.DataValue = 10;

 for (int i=0;i<50;i++)
 {
  tagChannelInfo stuChannelInfo;
  memset(&stuChannelInfo,0,sizeof(tagChannelInfo));
  
  for (int j=0;j<40;j++)
  {
   tagBeamInfo stuBeamInfo;
   memset(&stuBeamInfo,0,sizeof(tagBeamInfo));
   
   for (int z = 0;z < 30;z++)
   {
    tagGateInfo stuGateInfo;
    memset(&stuGateInfo,0,sizeof(tagGateInfo));
    
    strMsg.Format("GateName%d",z);
    strncpy(stuGateInfo.GateName,strMsg,strMsg.GetLength());
    stuGateInfo.GateValue = 20+z;
    
    stuBeamInfo.vGateInfo.push_back(stuGateInfo);
   }
   
   strMsg.Format("BeamName%d",j);
   strncpy(stuBeamInfo.BeamName,strMsg,strMsg.GetLength());
   stuBeamInfo.BeamValue = 30+j;
   stuChannelInfo.vBeamInfo.push_back(stuBeamInfo);
  }
  
  strMsg.Format("ChannelName%d",i);
  strncpy(stuChannelInfo.ChannelName,strMsg,strMsg.GetLength());
  stuChannelInfo.ChannelValue = 40+i;
  stuDataInfo.vChannelInfo.push_back(stuChannelInfo);
 }
 return TRUE;
}

 

 

调用:

 

void CMyDlg::OnBnClickedButton3()
{
 VectorTest vectorTest;
 tagDataInfo stuDataInfo;
 memset(&stuDataInfo,0,sizeof(tagDataInfo));
 vectorTest.GetVector(stuDataInfo);

 CString strMsg = NULL;

 //Get the
 strMsg.Format("GateName of Channle4_Beam2_Gate1_____________%s",stuDataInfo.vChannelInfo[3].vBeamInfo[1].vGateInfo[1].GateName);
 MessageBox(strMsg);
 
 

 int nGateCount = stuDataInfo.vChannelInfo[3].vBeamInfo[1].vGateInfo.size();

 int GateValue = stuDataInfo.vChannelInfo[3].vBeamInfo[1].vGateInfo[nGateCount-1].GateValue;

 strMsg.Format("%s",stuDataInfo.vChannelInfo[1].ChannelName);

 

}

 

posted on 2009-07-02 16:25  周伟  阅读(516)  评论(0编辑  收藏  举报

导航