Linked list

I have for homework assignment to create linked list and menu so user can input new entries as long as he want to. I don't want complete solution, only hints what to do. I can't figure out how to check if head of list(frist element) is allready allocated, i tried:

if (list) AND if (list==NULL) cout << "List allready exist",

but that doesn't work.
Last edited on
okay, i managed to write something i hope is correct.

if (list->next!=NULL) cout << "\nThere is no head of list, first you need to allocate it with #0\n\n";
else cout << "\nEnter new etc. etc.\n\n";
Normally, a linked list consists of both a Node class and a List class. The Node classes have the data, including the next pointer, while the List has a pointer to the first Node (and other meta-data if needed). You seem to have mixed up the two (using list->next).

Then, to check if the list is empty, you would do "if(myList.first == NULL)". Your code in the second post checks if the current element is the LAST element (i.e. no 'next' element, thus 'null' next pointer).
thank you, that's what i needed. :)
Topic archived. No new replies allowed.