Hello,
I wrote Linked List. I want to return nothing in the Delete method when Linked List is empty. How can fix my code? now when the linked list is empty, the program returns a strange number.
Is there a value you could use that would safely indicate that the list was empty, rather than being the value of Data in the deleted node? Say, zero? Or a negative value? Or INT_MAX? Or are those numbers that could be valid values of Data?
If not, you could try using boost::optional, although that's quite advanced for someone posting in the Beginners forum :)
delete is not deleting, it is doing a search. Perhaps a translation problem, but this is very confusing due to the name vs action done.
that aside you can't return 'nothing' to an integer. You can try a sentinel, or you can return some sort of structure that contains a 'not found invalid' boolean, or you can return a pointer to the data and set that to null if there is no data (this is a form of nothing).