Inserting Multiple Types Into Ordered Linked List

Hey everyone, so I'm having an issue or just not sure where to start. I have this program that creates a list then it will read the data from a file and store it into that list. I'm new to linked lists so I'm not sure where to begin with this.

Here is the data the program reads the order is key, last name, initial, dues.

6789 Towson J 65.25
3456 Johns K 200.00
1123 Stevens M 112.35
4489 Ellwood B 700.25
5555 Pryor R 99.99


So I have a class called MemberDO that basically just sets and gets the key value the last name the initial and the dues but there is one function called the readFrom File that is static that looks like this

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
void MemberDO::readFromFile(char *fname, orderedLinkedList<MemberDO>& list)
{
    int key;
    string last;
    char initial;
    double dues;
    ifstream file(fname);
    
    if(!file)
    {
        cerr << "File read error!" << endl;
    }
    
    while(file >> key >> last >> initial >> dues)
    {
        list.insert(MemberDO(key, last, initial, dues));
    }
}


So where I'm running into a problem is how do I insert all this into my linked list? Here is what I have for my linked list class and node struct so far.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
template <class Type>
struct nodeType
{
    Type info;
    nodeType<Type> *link;
};

template <class Type>
class orderedLinkedList
{
private:
    int count;                       
    
    nodeType<Type> *first;       
    nodeType<Type> *last;      
    
public:
    orderedLinkedList();
    int insert(const Type& newItem);
    Type *find(int location) const;
    int remove(int keyValue);
};

template <class Type>
orderedLinkedList<Type>::orderedLinkedList()
{
    first = NULL;
    last = NULL;
    count = 0;
}


I'm not sure where to begin with inserting the data into this list? It has multiple types are these all being stored in one Node? Also after I insert these items to the list I then need to return the key value of the item inserted to the list. This is how I will do the find and remove parts of the list, by the key value that is passed through the readFromFile function.

Here is an example of what my main part of the program is doing
1
2
3
4
5
6
7
8
9
int main()
{
    orderedLinkedList<MemberDO> memberList;
    MemberDO::readFromFile("Member.dat", memberList);
	
	// Test 1  - Key of 1st member on list
	checkTest("Test 1", 1123, (memberList.find(1))->getKey());
	// Test 2  - Lastname of 2nd member on list
	checkTest("Test 2", string("Johns"), (memberList.find(2))->getLastName());


Any help would be great the videos I watched basically over the ordered linked list from the book just doesn't make sense to me. Also note all my code is in one file unfortunately. It is not split up like it should be (not my choice)
Last edited on
Topic archived. No new replies allowed.