How do I make a function that produces a linked list?

How would I go about making a linked list by using a void function? I'm receiving my input from a text file, and I can manually go through and make the linked list, but I just found out I need to use a function to produce the linked list. Any help would be greatly appreciated!

You cannot just make a linked list using a void function. You need to design the data structure to hold each node, as well a a managing class to handle node insertion, deletion, etc. You could store your data in a vector.
> How would I go about making a linked list by using a void function?

Assuming that "void function" means "function with void return type":
pass by reference a linked list to the function, and let the function add items to that linked list.

For example, with the standard library list,
1
2
3
4
5
6
void foo( std::list<int>& the_list )
{
     the_list.push_back(1) ;
     the_list.push_back(2) ;
     // ...
}

Topic archived. No new replies allowed.