// Implementation of the RoadChunkList class // CSE143 Spring '01 // Homework 6 #include "road_chunk_list.h" #include // Construct an empty list RoadChunkList::RoadChunkList() { head = NULL; } // Destructor: delete all contained road chunk objects RoadChunkList::~RoadChunkList() { Node *temp; while (head != NULL) { temp = head->next; delete head; head = temp; } } // Draw all contained objects. void RoadChunkList::draw(GP142Display& gp) { Node *curr; for (curr = head; curr != NULL; curr = curr->next ) curr->chunk->draw(gp); } // Update all contained objects. void RoadChunkList::tick() { Node *curr; for (curr = head; curr != NULL; curr = curr->next ) curr->chunk->tick(); } // Prepend a new road chunk object to the list; the object must have been // allocated using "new", and will be deleted when the destructor for this // object is called. void RoadChunkList::addRoadChunk(RoadChunk *newChunk) { Node *oldHead = head; head = new Node; head->chunk = newChunk; head->next = oldHead; }