Creating Linked List From Array
Tough One Here:
I'm trying to, as the subject says, create a linked list from an array but I can't quite visualize it. Here's what I've got: I've created an array of nodes, each with next pointers. If this sounds confusing, hopefully you'll see what I mean by looking at the code. Anyway, I want to create seperate linked lists from each array node. Below is the code.
Class:
Code:
struct lettertype
{
keytype key; //string
};
struct binType
{
lettertype letter;
lettertype word;
binType* next;
};
typedef binType* subnodeptr;
class Something
{
public:
insertSub(binType letterBin[index], keytype key);
// keytype here is data to be entered into new node
private:
subnodeptr subLoc;
binType letterBin[MAX_ITEMS];
};
And here's the class implementation file:
Code:
void listType::insertSub(binType letterBin[index], keytype key)
{
subnodeptr newel; //create new pointer
sublen = sublen + 1;
newel = new binType; // create new node
newel->word.key = key; // insert data
if (letterBin[index]->next == NULL) // no list created
{
letterBin[index]->next = newel;
subLoc = letterBin[index]->next;
}
else // new node goes on the end of list
{
int loop = 0;
while (loop < 1)
{
subLoc = letterBin[index]->next;
if (subLoc->next == NULL)
{
subLoc->next = newel;
loop++;
}
else
subLoc = subLoc->next;
}
}
return;
}
Any idea's of what I'm doing wrong here?
Thanks,
bob2509