So I'm trying to make a basic singly linked list, without tail and going to use another class "CarObject" to add it to my CarList, which is basically my linked list. The only issue is that after writing out the code and testing it, nothing seems to print/work, i dont even get an error at all. I'm kind of lost and not sure what i did wrong.
UPDATE!: lets say we ignore my code, but how would you implement an add function to a linked list(no tail)
class CarList
{
class NodeType{
friend class CarList;
private:
CarObject* data;
NodeType* next;
};
public:
void addCar(CarObject*);
private:
NodeType *head;
};
void CarList::addCar(CarObject *car){
NodeType* newNode;
NodeType* currNode;
newNode = new NodeType;
newNode->data = car;
newNode->next = NULL;
currNode = head;
while (currNode != NULL) {
if (car->getYearModel().lessThan(currNode->data->getYearModel()))
break;
currNode = currNode->next;
}
newNode->next = currNode;
}
void CarList::print(){
NodeType* currNode = head;
while (currNode != NULL) {
currNode->data->printTheCarInfo();
currNode = currNode->next;
}
}