Array of Linked Lists - Please Help!

So far, I've figured out how to get strings from a text file and put them into linked lists, but I'm having trouble understanding and making an array of linked lists.

This is what I have so far:

Link for easier view of code: https://gist.github.com/anonymous/5486320
Link to entire program instructions: http://bg287.wordpress.com/category/csc210/

main.cpp
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include <fstream>
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdlib>
#include <string>
#include "compiler.h"
 
 
using namespace std;
 
nodeType* CreateList(string);
void outputlist(nodeType* , string);
 
 
 
int main ()
{
    ifstream infile;
    ofstream outfile;
    string inputfile, outputfile;
    nodeType* head;
    
    Compiler mylist;
    
    
    
    //getline(infile, mylist);
    cout<<"Input file name:"<<endl;
    getline(cin,inputfile);
    head = CreateList(inputfile);
    
    
    
    cout<<"Enter name of output file: ";
    getline(cin, outputfile);
    
    outputlist(head,outputfile);
    
    
    //out4<<hashtable[i]; // out4 is an ofstream object
    
    
    infile.close(); 
    outfile.close();
    
    
    return 0;
}
nodeType* CreateList(string filename)
{
    ifstream infile;
    infile.open(filename.c_str());
    nodeType* head = NULL;
    nodeType* compiled;
    compiled = new nodeType;
    
    while(infile && compiled != NULL)
    {
        getline(infile, compiled -> word);
        
        compiled->link = head;
        head = compiled;
        compiled = new nodeType;
        
    }
    delete compiled;
    infile.close();
    return head;
    }
 
void outputlist(nodeType* head, string outputfile)
{
    ofstream outfile;
    outfile.open(outputfile.c_str());
    
    nodeType* compiled;
    compiled = head;
    
    while(outfile && compiled !=NULL)
    {
        outfile << compiled -> word;
        outfile << endl;
        compiled = compiled -> link;
    }
    outfile.close();
}
 
 




compiler.cpp
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Filename: compiler.cpp
 
 
#include <iostream>
#include <cstdlib>
#include <fstream>
#include "compiler.h"
 
using namespace std;
 
 
Compiler::Compiler()
{
    current = NULL;
    //manynodes = 0;
}
 
 
bool Compiler::search_list(string item)
{
    nodeType *p, *first;
    
    p=first;  // 
    do {
        if(first->word==item)
        {
            return true;
        }
        p=p->link;
    } 
    while (first->link!=NULL);
    return false;
}
 
void Compiler::head_insert()
{
    
}
 
void Compiler::add_to_count()
{
    
}
 
ostream& operator<< (ostream & outfile, const Compiler & mylist)
{
    nodeType* head_ptr = mylist.current;
    
    
    while (head_ptr != NULL) //outputs the info of each node in list
    {
        outfile << head_ptr->word<<" ";
        head_ptr = head_ptr->link;
    }
    
    outfile << endl; //creates nwln for each list
    
    return outfile;
}





compiler.h
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Filename: compiler.h
 
 
#include <iostream>
#include <fstream>
#include <cstdlib>
 
using namespace std;
 
struct nodeType
{
    string word;
    int count;
    nodeType *link;
};
 
class Compiler
{
public:
    Compiler(); 
    bool search_list(string item);  // Tells the client whether a spcific value is                             
                                    //in the list. 
                                    // Calls a function search
    
    void head_insert();   // Should be a member function
    
    void add_to_count();  // Accesses the "current" pointer (in the private section)
                        // to update the count field of the node
                        // if the search is successful
    
    friend ostream & operator<< (ostream &outfile, const Compiler & mylist);
    // Overloaded operator to print both the data and the count field for each node
    
    //int size()const; // yields manynodes
    //void bubblesort();
    
    
protected:
    nodeType *search1_list; // Called by the public function search_list
                            // sets the private member current to the node to be 
                            // updated, or is NULL if the value is not there
    //int manynodes;
 
private:
    nodeType *current;      // Add to the bag class.
                            // This pointer will be used in the search and again
                            // used to update the node if the data is already present
};
 
//void list_clear(nodeType*& head_ptr);
//void list_copy(const nodeType*source_ptr, nodeType*& head_ptr, nodeType*& tail_ptr); 





input.txt
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
educe
line
educe
primrose
depart
line
thwart
line
grand
cellular
line
educe
depart
manage
depart
headline
empire
torch
headline
line
myth
deposit
balance
cellular
educe
distance




output.txt
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
 
distance
educe
cellular
balance
deposit
myth
line
headline
torch
empire
headline
depart
manage
depart
educe
line
cellular
grand
line
thwart
line
depart
primrose
educe
line
educe



Any help would be very much appreciated. Thanks!
Topic archived. No new replies allowed.