Implementing a recursive function to print a linked list in reverse order

Implement a recursive function named void printBack(DoublyLinkedNode<T>* node) for the class DoublyLinkedCircularList which will print out the elements in the list from back to front. The function is initially called with the first node in the list. You may not make use of the previous(prev) links


This is my solution where I got 2 out of a possible 3 marks:

1
2
3
4
5
6
7
8
9
10
template<class T>
void DoublyLinkedCircularList<T> :: printBack(DoublyLinkedNode<T>* node)
{
	if(node->next == NULL) //Correct- 1 mark
		return 0;
	else
		printBack(node->next); //Correct - 1 mark
		
		cout << current-> element << " ";
}


Can anyone help me figure out where I am losing a mark?
It does not print last element
1
2
	if(node->next == NULL) //If node is the last element
		return 0; //Do not print it 


And it does not print anything useful at all:
1
2
3
//What is the current?
//Did you meant node?
cout << current-> element << " ";
What is it that I need to do to fix it?
1
2
3
4
5
6
7
template<class T>
void DoublyLinkedCircularList<T> :: printBack(DoublyLinkedNode<T>* node)
{
	if(node->next != NULL)
		printBack(node->next);
	cout << node->element << " ";
}
Topic archived. No new replies allowed.