Hi everybody, I am now doing a lab assignment that uses this push funcion, and I'm having trouble understanding the instructions that the teacher provided.
This is what I came up with so far, and I know that the last two lines of codes does not match with the instruction, but I really don't know how to write that.
1 2 3 4 5 6 7
|
void StringOfCars::push(Car car)
{
Car *currentCarPtr;
Node *currentNodePtr;
new Node = currentNodePtr;
new Car(car) = currentCarPtr;
}
|
Here is the lab instruction:
1) Declare a local pointer variable of type Car * named currentCarPtr.
2) Declare a local pointer variable of type Node * named currentNodePtr.
3) Use new to get space in the heap for a Node and save the address of the space in the heap in currentNodePtr
4) Use new get space in the heap for a new Car that is a copy of the car
5) parameter of the push function and save the address of the space in the heap in currentCarPtr
6) Set the data pointer in this new Node object to point to the new Car object.
If the head pointer is zero
set the head and the tail pointer to the value of currentNodePtr
else
set the next pointer of the Node object pointed to by the tail pointer to the value of currentNodePtr
set the next pointer to the value of the currentNodePtr