I had the following question in my exam and got 2 out of a possible 6 marks
Here is the question:
Implement a function for the DoublyLinkedCircularList class with the signature addToTail(T element) which will append the element passed in as a parameter to the back of the list
Here is my solution
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
template<class T>
void DoublyLinkedCircularList<T> :: addToTail(T element)
{
DoublyLinkedNode<T>* head;
DoublyLinkedNode<T>* temp;
temp->element = element;
if(tail == null)
{
tail = temp;
temp -> next = temp; //Wrong
}
head = tail->next;
tail->next = temp; //Correct - mark
temp -> next = head; //Correct - mark
}
I basically only got marks for the last two lines of code
Can anyone help me figure out the correct way to complete this question?