Problems with searching in linked lists

Hello everyone!
So I have a Class named Subject, wich I used linked list to keep the objects.
Now I have another Class called Tests which I should register a test by the Subject class, so I made a search like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
List obj; //it's the object to access the List class, which manipulates the 
//nodes from Subject.

obj.currentPtr=obj.firstPtr;

      while (obj.currentPtr!=NULL)
        {  

		if(obj.currentPtr->nameSubject==value) //searching if there's a
                 return obj.currentPtr;                //name equal to provided

                obj.currentPtr=obj.currentPtr->nextPtr;
       }
        return 0;


I've made a similar process for Subject. But in this when I access the firstPtr, it's shown to be 0, once I have already the list of Subject and it should not be zero.

What's wrong?

Thank you!
Last edited on
Then the problem is in how you are inserting information into the linked list...need to see more code to debug further
There is a class List, which makes the manipulation of the linked list for Subject, the insertions are right, but as I said, when I try to access this objects of the linked list, the firstPtr (data member of List) which there is already data in it, returns zero, like there was no data in it.
My insertion in List, which manipulates data from Subject:

1
2
3
4
5
6
7
8
9
10
11
12
13
Subject *newPtr= getNewNode();//function just to allocate correctly the node
    if(isEmpty()) //check if the list is empty
        {
 	 firstPtr=lastPtr=newPtr;
	 newPtr->nextPtr=0;
	 newPtr->getDataFromUser();//method for getting the data need to fullfil the object data members
         }
    else{
            newPtr->nextPtr=firstPtr;
            firstPtr=newPtr;
	    newPtr->getDataFromUser();
        }


So I'm trying to access the member *firstPtr which is from List, but I think when I create the object the constructor set firstPtr=0, how can I access the firstPtr from List by the class Test?
I figured out a way to do it.
Anyway, thank you for reply
Topic archived. No new replies allowed.