Double linked list

Hello,
I am a nube in C++ and I need your help.
I want to make a double linked list wich will be a street to conect city A(Begining of list) and city B(End of list) and every node will be a car.
So far I can do it, but I have to declare the distance between the cities. Also , every 5 seconds the distance of the nodes (cars) from city A must change according to the speed of the car.

Please , any help will do
Thank you.
closed account (Lv0f92yv)
I take it each car node has a speed field. Do you want the list sorted in order of which car is closest to city A or B?

If this is the case, each car node should probably have a field for distance from the target, and every x seconds, that is the distance you will change for each car depending on it's speed. Then, after the update, re-sort the list by distance from target city.

[Edit]Your distance update function for each car node could be something simple like, carnode.updateDistance( optional param ) { myDistanceFromCityA -= speed * .5; }, where .5 is some constant, which you could of course make more sophisticated.
[/Edit]

As far as the waiting is concerned, consider using the ctime header: http://www.cplusplus.com/reference/clibrary/ctime/

Without seeing any code, I can only assume you have a doubly linked list implemented.

You seem to want the city (A and B) nodes to also be in the list - a dirty trick might be to do this in sentinel nodes, but otherwise, you might need separate nodes/objects to represent your cities.
Last edited on
Topic archived. No new replies allowed.