I'm building a Skip List for a program. So far, I've managed to be able to only insert in the correct order to the bottom level. There are 5 other levels above the bottom level where nodes are not being inserted into. I debugged my program and found that the code is indeed running, and it's doing something. However, when the Skip List is printed to the console, it only prints the bottom row and shows that top 5 rows as empty.
All the other code, such as printing, is correct because it was provided for this program. I just have to write the insert function. I also know the first half of my insert function is correct because my output is showing that Nodes are being inserted to the bottom most level. My issues is with adding nodes to the upper levels.
Node *lowerNode = newNode; // These two pointers point to the new Node that was added to the bottom level successfully.
Node *current = newNode;
int inserting = rand() % 2;
int levelCount = 1; // we are randomly deciding if nodes will be added to the next level.
while((inserting == 1) && (levelCount < LEVEL - 1)) // Level = 6
{
Node *newNode2 = new Node;
newNode2->item = obj;
while(current->up == NULL && current->prev != NULL)
{
current = current->prev;
}
current = current->up;
newNode2->next = current->next;
current->next->prev = newNode2;
newNode2->prev = current;
current->next = newNode2;
newNode2->down = lowerNode;
newNode2->up = NULL;
lowerNode = newNode2;
current = newNode2;
inserting = rand() % 2;
levelCount++;
}