本文整理汇总了C++中DynamicArray::getIndex方法的典型用法代码示例。如果您正苦于以下问题:C++ DynamicArray::getIndex方法的具体用法?C++ DynamicArray::getIndex怎么用?C++ DynamicArray::getIndex使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DynamicArray
的用法示例。
在下文中一共展示了DynamicArray::getIndex方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: road
std::vector<Road> Algorithm::findShortestPath(MultiGraph<double, Station>* graph, Station* start, Station* end ,double &lenght)
{
DynamicArray<Station> *stations = graph->getVertexs();
std::vector<Road> result;
if (stations->getIndex(start) != -1 && stations->getIndex(end) != -1)
{
DynamicArray<Station> *vertexs = graph->getVertexs();
int size = vertexs->getSize();
double* arr = new double[size*size];
Graph g;
g.resize(size);
for (int i = 0; i < size; i++)
{
Station*startTemp= vertexs->get(i);
for (int j = 0; j < size; j++)
{
Station*endTemp = vertexs->get(j);
DynamicArray<double>* values = graph->getLenghtsByStation(startTemp, endTemp);
if (values != 0 && values->getSize() > 0)
{
double value = Algorithm::findMin(values);
arr[j*size + i] = value;
g[i].push_back(std::make_pair(j, value));
}
}
}
std::vector<int> path;
int startIndex = vertexs->getIndex(start);
int endIndex = vertexs->getIndex(end);
dijkstra(g, startIndex, endIndex, path);
double sum = 0;
for (int i = path.size() - 1; i >= 0; i--)
{
if (i - 1 >= 0)
{
Station * resultStart = vertexs->get(path[i]);
Station * resultEnd = vertexs->get(path[i - 1]);
Road road(resultStart, resultEnd);
result.push_back(road);
sum += arr[path[i - 1] * size + path[i]];
}
//std::cout << path[i] << "->";
}
//cout << "\n";
//cout << sum;
lenght = sum;
delete[] arr;
}
return result;
}