On Saturday, 9 May 2015 14:42:49 UTC+3, Paul wrote:
> (No, this is not homework.)
If it is not homework then better learn to use 'std::forward_list<int>'.
Standard library containers are more efficient and well tested than
self-made. Better learn to use other standard library containers
first since linked list is among least efficient container for majority
of container usages.
> I'm attempting to write code to deallocate
> the memory of a linked list and set its head pointer to zero. My
> code compiles. However, I don't know of an easy way to test it.
Tests are usually little command-line programs that only deal with
one or few closely related classes. Basically you can test that
"delete list" with 3 test calls: call the function with empty list,
call it with list that contains one element and call with list of
million of elements.
You can use a class with user-written constructors and destructor
as 'data' instead of 'int' so you can count in those that all of the
elements are added and removed like you did plan. Also it might be
worth to time that last call to find out its performance.
> I have two solutions, one recursive and one non-recursive. I'd be
> very grateful if someone could tell me if/how either have problems,
> or whether both solutions are ok.
The functions you posted seem OK to me.
It might be worth to note that abilities to test and to debug your
work yourself are very important skills to have. When you constantly
commit defective code then it will be noticed by your team-mates since
it is negative work. ;) Team would overall gain if you did look
YouTube instead of writing bad code and that is rather bad news to you.