[School] Linkedlist *pointers.

Good morning,

I've a question about global pointers.
At first, my assingment:
We need to read a .txt and only pickout the words no other operators.
(No problems with that) then we need to put the word in a class (pointed to this class by a pointer (*current) then after done this, we need to create a linked list.
BUT
This sortinglist must be placed in a other file (linkedlist.cpp), so I thought I'll create a couple of global pointers that can be used by the main.cpp and the linkedlist.cpp the are decleared in Class.h (here stands my class) but theres a problem, this will give errors.

Any thoughts, comments and help would be greatly appreciated.

Greets,
Leek007

Example:

class ReadFile{
class pPrev;
class pNext;
std::string sWord;
int iindex;
};

Now I couple the words: Hello and World on this class by:
Class *current, *last, *first;

Current->sWord = "Hello";
Current->iindex = Icount; //(1)
now I say: current = first;
Current->sWord = "World";
Current->iindex = Icount; //(2)
current = first;
And now we need to sort the words.
(oke there is no need for sorting here, but in my file there is.)

I call the sort function.
Sort(); // No arguments, beceause I wan't to use global pointers.

And there the pointers won't exists.

in both files the class ReadFile is included.
#include "Class.h"



are u using the extern keyword?
Why do you want to use global pointers? That's a bit like saying "meh, I suppose I could make this function actually useful, but I don't really feel like it today".
@NtSzar:
I'm sorry what do you mean with a extern keyword?

@hanst99:
Haha, I know I could change it and then go back to the main function and search for the first and last pointer, by going to the end of current for last and going to the top of current for the first. But I thought this is looking better?
But you think its not? Why not? its easier right?
Last edited on
I'm a bit confused by your question...
For this assignment do you need to write your own linked list (http://en.wikipedia.org/wiki/Linked_data_structure) class? Or can you use STL (http://en.wikipedia.org/wiki/Standard_Template_Library)
I found out how to use the pointers. Oke its not exactly what I attended but it works fine! Even hanst99 could be happy with.
I'll post my code on the end of this day.

Oke its a bit later.

Here is my solution:
class:

1
2
3
4
5
6
7
8
9
10
11
12
13
lass Gev{			        		
public:  
    class Gev *pPrev;       	
    class Gev *pNext;           
    int iinhoud;				
    int iwteller;				
    string sWoord;		  
    Gev(){
        iinhoud     = 0;			
        iwteller    = 0;
        sWoord.clear();    
    }
};



in my main I give the first and the last pointers, pointing towards the class, along with the function.
Plink.Sorteer(eerste, laatste);

Then I use this pointers to sort the list of the linkedlist file.
how do I return both pointers?
I don't, I changed the index number of every word after sorting them out.
So when I'm back in the main function I solve it like this:

1
2
3
4
5
6
7
8
while(huidige->pPrev != NULL){
        huidige = huidige->pPrev;
    }
    laatste = huidige;
    while(huidige->pNext != NULL){
        huidige = huidige->pNext;
    }
    eerste = huidige;


In this way the pointers are orded right and then file making begins.

Thanks for the help and I'll tell you what I've got for the assigment.
Last edited on
Topic archived. No new replies allowed.