I've inherited some legacy code that I need to modify. The code that needs to be modified uses Linked Lists. I'm familiar with the concept of linked lists and used them extensively in the distant past but not in C++.
The code I need to modify manages a linked list that has 4 linked lists as data elements. The 4 sub lists are synchronized with each other - the first elements in each sub list go together, the second elements in each sub list go together, the third elements in each sub list go together, etc. There is no set number of nodes possible for the sub lists, but they must all be the same length.
A 5th data type has been added to each set, which means I need a 5th sub list. After all of nodes in all of the linked lists have been populated, I have to go back and perform math on the data contained in two of the lists based on the value in the new 5th list (which is based on an enumeration) and then put the result back into the 1st list.
Here's the basic format:
- Main List
-- Sub List 1 - data
-- Sub List 2 - data
-- Sub List 3 - data
-- Sub List 4 - data
-- Sub List 5 - data type (enumeration)
I've got two problems I need help with: (1) how to correctly read the value contained in SL5, and (2) how to put the data back into a node in SL1.
I want to be able to do the above without writing my own linked list management routines.
Here's an example of my code (I can't give the actual code because of the nature of the project).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
DataTypeEnum firstDataTypeA;
double tempDataType1;
double tempDataType2;
double tempDataType3;
int numNodes;
LinkedList* tempList;
for (int x=0; x,numNodes; x++)
{
//I need help here, because this gives me a data exception at runtime
firstDataTypeA = *(( DataTypeEnum)tempList->tempExtraData.dataTypeA->GetPointer(x));
if (firstDataTypeA = DataTypeEnumOne)
{
tempDataType1 = *((double) tempList->tempExtraData.dataType1->GetPointer(x));
tempDataType2 = *((double) tempList->tempExtraData.dataType2->GetPointer(x));
tempDataType3 = tempDataType1/ tempDataType2;
//This is where I can't get the syntax correct. I know the below isn't correct, but it is
// logically what I want to do. I've tried many different combinations of indirection, etc.
//"currentnode" is not an actual piece of code...it's a place holder to help explain what I want to do
tempList->tempExtraData.dataType1.currentnode = tempDataType3;
tempList->tempExtraData.dataTypeA.currentnode = DataTypeEnumTwo;
}
}
|
So, as I stated earlier I need help with
1. Reading an enumeration value from a node in a linked list (line 11).
2. How to change a value in a node without rebuilding the whole sub list (lines 21 & 22).
For #2, I think it has to do with indirection and/or pointing to the address of the node, I just haven't been able to get the syntax right so that I can get it to compile.
Some additional details: we are using VS2005 on Win XP. I do not have the option of upgrading either VS2005 or using a different OS.
Thanks,
gk