本文整理汇总了C++中CList::FindIndex方法的典型用法代码示例。如果您正苦于以下问题:C++ CList::FindIndex方法的具体用法?C++ CList::FindIndex怎么用?C++ CList::FindIndex使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CList
的用法示例。
在下文中一共展示了CList::FindIndex方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: OnAllVideoTypes
BOOL CNetClient::OnAllVideoTypes()
{
//CMainFrame *pWnd=(CMainFrame*)AfxGetMainWnd();
//CTypeManager typeMgr(&pWnd->m_adoConnection);
CTypeManager typeMgr(&g_pWnd->m_adoConnection);
CList<CType,CType> lstType;
typeMgr.GetAllType(&lstType);
CType type;
CString strData;
//发送的字符串的格式:"战争片,1,喜剧片,2,古装片,3 "
for (int i=0;i<lstType.GetCount();i++)
{
type=lstType.GetAt(lstType.FindIndex(i));
strData+=type.strTypeName;
strData+=",";
CString strID;
strID.Format("%d,",type.nTypeID);
strData+=strID;
}
//首先发送数据长度,然后发送数据
int nLen=strData.GetLength();
LPSTR pData=(LPSTR)malloc(nLen+1);
memset(pData,0,nLen+1);
strcpy(pData,strData);
SendData(VODNETCMD_TYPES_RET,pData,strData.GetLength());
free(pData);
return TRUE;
}
示例2: OnVideosByTypeID
BOOL CNetClient::OnVideosByTypeID()
{
//接收客户端的数据
GETVIDEOS getVideo;
if (!RecvData(&getVideo,sizeof(getVideo)))
{
return FALSE;
}
//数据库查询指定类型ID的所有视频
//CMainFrame *pWnd=(CMainFrame*)AfxGetMainWnd();
//CVideoManager videoMgr(&pWnd->m_adoConnection);
CVideoManager videoMgr(&g_pWnd->m_adoConnection);
CList<CVideo,CVideo> lstVideo;
videoMgr.GetVideosByTypeID(getVideo.typdID,&lstVideo);
//返回给客户端数据,返回的视频信息的格式,
//"敢死队,1,泰囧,22,西游记,31 "
CVideo v;
CString strData;
for (int i=0;i<lstVideo.GetCount();i++)
{
v=lstVideo.GetAt(lstVideo.FindIndex(i));
strData+=v.strVideoName;
strData+=",";
CString strID;
strID.Format("%d,",v.nVideoID);
strData+=strID;
}
//首先发送数据长度,然后发送数据
int nLen=strData.GetLength();
LPSTR pData=(LPSTR)malloc(nLen+1);
memset(pData,0,nLen+1);
strcpy(pData,strData);
SendData(VODNETCMD_TYPES_RET,pData,strData.GetLength());
free(pData);
return TRUE;
}
示例3: OnBnClickedButtonReverseA
/**
* 响应鼠标单击按钮;Reverse
* @param CBCGPGridCtrl* pGridCtrlEdit 输入行
* @param CBCGPGridCtrl* pGridCtrlList 列表
* @param CList<int, int>* plsNb Nb号队列指针
* @return void
*/
void CGridCtrlOperation::OnBnClickedButtonReverseA(CBCGPGridCtrl* pGridCtrlEdit, CBCGPGridCtrl* pGridCtrlList)
{
CList<int, int> ListNb;
CList<int, int>* plsNb = &ListNb;
// 得到索引队列,修改操作、删除操作、颠倒操作
if(false == GetIndexListForChangeOrDeleteOrReverse(pGridCtrlEdit, pGridCtrlList, plsNb))
{
return;
}
CBCGPGridRow* pRow = NULL; // 行
CBCGPGridRow* pRowMax = NULL; // 排序行
CBCGPGridRow* pRowNew = NULL; // 新行
CList<int, int> olsNb;
int iNbStart = -1;
int iNbEnd = -1;
int iRowIndex = -1;
int i, j;
POSITION posMax;
POSITION pos;
int iNbMax;
int iNb;
// 得到Nb队列
for(i = 0; i < plsNb->GetCount(); i++)
{
pos = plsNb->FindIndex(i);
iRowIndex = plsNb->GetAt(pos);
iNb = pGridCtrlList->GetRow(iRowIndex)->GetData();
olsNb.AddTail(iNb);
if(0 == i)
{
iNbStart = iNb;
}
if((plsNb->GetCount() - 1) == i)
{
iNbEnd = iNb;
}
}
// 对Nb排序,由小到大
for(i = 0; i < olsNb.GetCount(); i++)
{
posMax = olsNb.FindIndex(i);
iNbMax = olsNb.GetAt(posMax);
for(j = i + 1; j < olsNb.GetCount(); j++)
{
pos = olsNb.FindIndex(j);
iNb = olsNb.GetAt(pos);
if(iNbStart < iNbEnd)
{
if(iNbMax > iNb)
{
iNbMax = iNb;
posMax = pos;
}
}
else
{
if(iNbMax < iNb)
{
iNbMax = iNb;
posMax = pos;
}
}
}
olsNb.RemoveAt(posMax);
olsNb.AddHead(iNbMax);
}
for(i = 0; i < plsNb->GetCount(); i++)
{
pos = plsNb->FindIndex(i);
iRowIndex = plsNb->GetAt(pos);
pRow = pGridCtrlList->GetRow(iRowIndex);
posMax = olsNb.FindIndex(i);
iNbMax = olsNb.GetAt(posMax);
pRowMax = pGridCtrlList->FindRowByData(iNbMax);
pRowNew = pGridCtrlList->CreateRow(pGridCtrlList->GetColumnCount());
pGridCtrlList->AddRow(pRowNew, FALSE);
pRowNew->SetData(pRow->GetData());
pRowNew->GetItem(0)->SetValue(pRow->GetItem(0)->GetValue());
for(int j = 1; j < pGridCtrlList->GetColumnCount(); j++)
{
COleVariant oVariant = pRow->GetItem(j)->GetValue();
pRowNew->GetItem(j)->SetValue(oVariant);
//.........这里部分代码省略.........
示例4: crossoveroperator
//current 变化后,以上没有问题了。
void Genetic::crossoveroperator()
{
//非均匀算术线性交叉,浮点数适用,alpha ,beta是(0,1)之间的随机数
//对种群中两两交叉的个体选择也是随机选择的。也可取beta=1-alpha;
//current的变化会有一些改变。
int i,j;
double alpha,beta;
CList <int,int> index;
int point,temp;
double p;
// srand( (unsigned)time( NULL ) );
for (i=0;i<popsize;i++)//生成序号
{
index.InsertAfter (index.FindIndex(i),i);
}
for (i=0;i<popsize;i++)//打乱序号
{
point=rand()%(popsize-1);
temp=index.GetAt(index.FindIndex(i));
index.SetAt(index.FindIndex(i),
index.GetAt(index.FindIndex(point)));
index.SetAt(index.FindIndex(point),temp);
}
for (i=0;i<popsize-1;i+=2)
{
//按顺序序号,按序号选择两个母体进行交叉操作。
p=double(rand()%10000)/10000.0;
if (p<crossoverrate)
{
alpha=double(rand()%10000)/10000.0;
beta=double(rand()%10000)/10000.0;
current=population.GetAt(population.FindIndex(index.GetAt(index.FindIndex(i))));
current1=population.GetAt(population.FindIndex(index.GetAt(index.FindIndex(i+1))));//临时使用
current1代替
for(j=0;j<variablenum;j++)
{
//交叉
double sign;
sign=rand()%2;
if(sign)
{
current.chromosome[j]=(1-alpha)*current.chromosome[j]+
beta*current1.chromosome[j];
}
else
{
current.chromosome[j]=(1-alpha)*current.chromosome[j]-
beta*current1.chromosome[j];
}
if (current.chromosome[j]>variabletop[j]) //判断是否超界.
{
current.chromosome[j]=double(rand()%10000)/10000*(variabletop[j]-variablebottom[j])+
variablebottom[j];
}
if (current.chromosome[j]<variablebottom [j])
{
current.chromosome[j]=double(rand()%10000)/10000*(variabletop[j]-variablebottom[j])+
variablebottom[j];
}
if(sign)
{
current1.chromosome[j]=alpha*current.chromosome[j]+
(1- beta)*current1.chromosome[j];
}
else
{
current1.chromosome[j]=alpha*current.chromosome[j]-
(1- beta)*current1.chromosome[j];
}
if (current1.chromosome[j]>variabletop[j])
{
current1.chromosome[j]=double(rand()%10000)/10000*(variabletop[j]-variablebottom[j])+
variablebottom[j];
}
if (current1.chromosome[j]<variablebottom [j])
{
current1.chromosome[j]=double(rand()%10000)/10000*(variabletop[j]-variablebottom[j])+
variablebottom[j];
}
}
//回代
}
newpopulation.InsertAfter (newpopulation.FindIndex(i),current);
newpopulation.InsertAfter (newpopulation.FindIndex(i),current1);
}