How to retrieve the last node in a linked list?

Class EmployeeList

javascript:tx(
'string employeeList::searchLastEmployee (nodeType<employeeInfo>* &last){
return last->data.getCode ();
}

string employeeList::showLastEmployee (){
return searchLastEmployee (last);
}
')


Main:


javascript:tx('
int main()'{
EmployeeList emp;
createEmployeeList (emp);
cout<<"Last employee code : "<<emp.showLastEmployee ()<<endl;
}
)


May I know why this doesn't work? I've read the data from a file and when I print it, the entire list comes out, but it just couldn't print out the last data on the list..
a classic linked list of pointers, you would iterate the list until you hit the node where 'next' is 'null' and return that one. The STL list does this for you.
I got it, thanks!
Actually, I believe that std::list maintains a pointer to the last item so that back() can return the result in constant time.
Topic archived. No new replies allowed.