Linked list

Hi, i have some problem with linked list.

This my main class
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
class StockList //stock list
{
public:
    StockList();
    ~StockList();
    int getLengthStock() const;
    int getLengthWait() const;
	void LoadDVDList(string filename); // read dvd file
	void LoadWaitList(string filename); // read dvd file
	void Retrieve(int index,string& ID,string& title,int& year,int& have,int& want);
	void RetrieveWaitList(StockList& aLis,int index,string& who);
private:

    class StockItem //stock item
    {
    public:
		StockItem();
		~StockItem();
		void Set_Data(string ID,string title,int year,int have,int want);
		string Get_ID();
        string Get_title();
        int Get_year();
        int Get_have();
        int Get_want();


    private:
        string ID;
        string title;
        int year, have, want;
    };

	struct WaitNode
    {
        string ID;
        string who;
        WaitNode *next;
    };
    int wsize;
    WaitNode *whead;
    WaitNode *find_wait(int index) const;
/********************************/
    struct StockNode //node for inventory list of stock items
    {
        StockItem item;
        WaitNode *waitHead,*waitTail;
        StockNode *next;
    };
	int size;
    StockNode *head; // pointer to first stock node on the list
    StockNode *find(int index) const;
};


my problem is how can i retrive data from member in Waitnode for every node in StockNode?

I managed to add data in Waitnode. here is the code
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
void StockList::LoadWaitList(string filename)
{
    string CurrentID, ID, who;
    int index = 1;
    int Listpos=1;
    //int length = 1;
    StockNode * cur;
    whead = cur->waitHead;
    char str[256];
    while (index < getLengthStock())
    {
        cur = find(index);
        CurrentID = cur->item.Get_ID();
        #ifdef DEBUG
        cout << CurrentID << endl;
        #endif
        ifstream in("waitlist.txt");
        while (in)
        {
            if (in.getline(str, 256, '"'))
            {
                in.getline(str, 256, '"');
                ID = (string)str;
                if (in.getline(str, 256, '"'))
                {
                    in.getline(str, 256, '"');
                    who = (string)str;
                    in.getline(str, 256, '\n');
                    if(CurrentID == ID)
                    {
                        WaitNode * newPtr = new WaitNode;
                        newPtr->ID = ID;
                        newPtr->who = who;
                        if (Listpos == 1)
                        {
                            #ifdef DEBUG
                            cout << "New waiting list created in node " << CurrentID << endl;
                            #endif
                            newPtr->next = whead;
                            whead = newPtr;
                            #ifdef DEBUG
                            cout <<who<< " added to " << CurrentID << endl;
                            #endif
                            Listpos++;
                        }
                        else
                        {
                        WaitNode *cur = whead;
                        for (int skip = 1; skip < index - 1; ++skip)cur = cur->next;
                        WaitNode*prev = cur;
                        newPtr->next = prev->next;
                        prev->next = newPtr;
                        #ifdef DEBUG
                        cout <<who<< " added to " << CurrentID << endl;
                        #endif
                        Listpos++;
                        }
                    }
                }
            }
        }
        Listpos=1;
        in.close();
        index++;
    }
}


Thanks in advance

Topic archived. No new replies allowed.