本文整理汇总了C++中Queue::GetLength方法的典型用法代码示例。如果您正苦于以下问题:C++ Queue::GetLength方法的具体用法?C++ Queue::GetLength怎么用?C++ Queue::GetLength使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Queue
的用法示例。
在下文中一共展示了Queue::GetLength方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Run
void BFS::Run(int** matrix, int size, int start)
{
int index = -1;
Queue* queue = new Queue();
SNode* node = new SNode();
node->value = start;
queue->EnQueue(node);
while(queue->GetLength() != 0)
{
node = queue->DeQueue();
index = node->value;
this->labels[index] = 1;
delete node;
for(int i=0; i<size; i++)
{
if(matrix[index][i] == 1 && this->labels[i] == 0)
{
node = new SNode();
node->value = i;
queue->EnQueue(node);
this->labels[i] = 1;
this->previous[i] = index;
}
}
node = NULL;
}
delete queue;
}
示例2: Run
void Prim::Run(int** matrix, int size, int start)
{
bool isStop = false;
SEdge* edgeMin = NULL;
this->label[start] = 1;
Queue* queue = new Queue();
SNode* node = new SNode();
node->value = start;
queue->EnQueue(node);
while(this->result->GetLength() != this->size - 1 && isStop == false)
{
edgeMin = NULL;
for(int i=0; i<queue->GetLength(); i++)
{
node = queue->GetIndex(i);
for(int j=0; j < size; j++)
{
if(matrix[node->value][j] != 0 && this->label[j] == 0)
{
if(edgeMin == NULL)
{
edgeMin = new SEdge();
edgeMin->x = node->value;
edgeMin->y = j;
edgeMin->value = matrix[node->value][j];
}
else
{
if(matrix[node->value][j] < edgeMin->value)
{
edgeMin->x = node->value;
edgeMin->y = j;
edgeMin->value = matrix[node->value][j];
}
}
}
}
}
if(edgeMin != NULL)
{
this->result->Add(edgeMin);
this->sum += edgeMin->value;
this->label[edgeMin->x] = 1;
this->label[edgeMin->y] = 1;
node = new SNode();
node->value = edgeMin->y;
queue->EnQueue(node);
}
else
{
isStop = true;
}
}
delete queue;
}