Answer to Question #13132 in C++ for JX

Question #13132
How should I modify this coding to linked list without using the STL vector. TQ

void printRoute(GRAPH graph[], string destination, GRAPH* graphPtr, Node* ptr, vector<string>&s, const int originIndex)
{
static bool reachable = false;
while(ptr != NULL)
{
if(ptr->city == destination)
{
reachable = true;
s.push_back(ptr->city);
for(int i = 0; i < s.size(); i++)
{
cout<<" --> "<<s[i];
}
cout<<endl;
return;
}
//cout<<ptr->city<<" --> ";
s.push_back(ptr->city);
if (findIndex(ptr->city, graph) != -1)
printRoute(graph, destination, &graph[findIndex(ptr->city, graph)], graph[findIndex(ptr->city, graph)].node.nextPtr, s, originIndex);
ptr = ptr->nextPtr;
s.pop_back();
if(graphPtr == &graph[originIndex] && s.size() > 1) s.resize(1);
cout<<endl;
}
s.pop_back();
if(graphPtr == &graph[originIndex] && !reachable)
cout<<"Cannot be reached"<<endl;

}
};
0
Expert's answer

Answer in progress...

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS