?
Solved

Nested Linked List Sort/Search

Posted on 2003-02-26
5
Medium Priority
?
208 Views
Last Modified: 2012-08-14
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
Comment
Question by:pimonkey
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 8

Accepted Solution

by:
akshayxx earned 300 total points
ID: 8026082
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
 
LVL 8

Expert Comment

by:akshayxx
ID: 8026090
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
 

Author Comment

by:pimonkey
ID: 8030469
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
 

Author Comment

by:pimonkey
ID: 8030481
Nice enthusiasm, Too bad I did not provide all information needed and made it confusing.

mmmm...points taste good yes?
0
 
LVL 8

Expert Comment

by:akshayxx
ID: 8030757
>>>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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
Suggested Courses

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question