• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 210
  • Last Modified:

Nested Linked List Sort/Search

I have two linked list nodes:

struct ClassNode
     {
                //Other variables not important
          ClassNode * next;
          ClassNode * previous;
     };

struct StudentNode
     {
          apstring fullName;
          ClassNode * classHead;
          StudentNode * next;
          StudentNode * previous;
     };

Previously in my program, a linked list of Students was created and the variable "studentHead" was passed to function CountClasses, by reference.  studentHead is the head pointer for the created linked list.  (Function CountClasses moves through the Student list and creates/addsto another linked list of Class Names)

Here is the important section of CountClasses:

ClassNode * currentStoredClass= new ClassNode;
     StudentNode * currentStoredStudent = new StudentNode;
     currentStoredStudent = studentHead->next;
     currentStoredClass = currentStoredStudent->classHead->next;

while (currentStoredStudent->next != NULL)
     {
          while (currentStoredStudent->currentStoredClass->next != NULL)
          {
               foundClass = FindClass(currentStoredStudent->currentStoredClass,tempHead);
               if (foundClass == NULL)
               {
                    tempClass->previous = lastClass;
               }
               if (foundClass != NULL)
               {
                    tempClass = foundClass;
                    tempClass->studentsApplying++;
               }
               currentStoredStudent->currentStoredClass = currentStoredStudent->currentStoredClass->next;
          }
          currentStoredStudent = currentStoredStudent->next;

---------------
The error recieved is that currentStoredClass is not a member of StudentNode.   I want to assign currentStoredClass to the ClassNode within the first Student in the Student Linked List.   this probably is not the best way, but I am open to any suggestions.
0
pimonkey
Asked:
pimonkey
  • 3
  • 2
1 Solution
 
akshayxxCommented:
members of StudentNode are

         {
          apstring fullName;
         ClassNode * classHead;
         StudentNode * next;
         StudentNode * previous;
}

currentStoredClass is certainly not its member..

>>>I want to assign currentStoredClass to the ClassNode within the first Student in the Student Linked List.  

since u have declared

ClassNode  *currentStoredClass ;
and
what does ur studentHead points to ? does it point to the head of the Student List ?


then to acheive what u said above will be
currentStoredClass = studentHead->classHead;

only this single statement will do the job
0
 
akshayxxCommented:
does it point to the head of the Student List ?
OR its the headPointer itelf .. so it will point to the first student itself..

by first student .. do u mean the one at the end of the list ?? or the one at the head of the list ??
0
 
pimonkeyAuthor Commented:
though I truely value your commitment to my problem, I have found the answer.  My lack of information made it very difficult to figure out what was going on.

The answer is to change:

ClassNode * currentStoredClass= new ClassNode;
 -TO-

ClassNode * currentStoredStudent->currentStoredClass= new ClassNode;



0
 
pimonkeyAuthor Commented:
Nice enthusiasm, Too bad I did not provide all information needed and made it confusing.

mmmm...points taste good yes?
0
 
akshayxxCommented:
>>>mmmm...points taste good yes?
not really .. what tastes better is that u solved something , which other people had hard time doing .. points is a token which tells how hard and important was it for the asker :)
and 'the expert' can also feel being valuable :)
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now