Jun 24, 2012 at 1:12pm UTC
Hi
In the function below, I need to handle the case if the singleLinkList is empty.
One option will be throw exception. But if I have made not to use exception here, what will be alternate way to handle such situation.
Thanks
1 2 3 4 5 6 7 8 9 10 11
template <typename T>
Node<T>& SingleLinkList<T>::InsertAfter(const Node<T>& node, const T& data) {
if (this ->IsNodeValid()) {
Node<T>* newNode = new Node<T>(data);
newNode->SetNext(node.GetNext());
node.SetNext(newNode);
return newNode;
}
else {
}
}
Last edited on Jun 24, 2012 at 2:12pm UTC
Jun 24, 2012 at 2:06pm UTC
I can't see the function returning a value. Should it?
Jun 24, 2012 at 2:13pm UTC
Sorry, I had copied wrong function. I have corrected it.
Jun 24, 2012 at 2:14pm UTC
How can a node be invalid and why would someone pass such a node to the function?
Jun 24, 2012 at 2:49pm UTC
In that function there is constraint that the node should not be null and must be a member of list.