Any time values get entered into the list nothing happens nor have they been added. Here's a sample of what I've done but I'm getting a little confused whats wrong with it.
int main()
{
// The beginning node in the linked list.
Node *pFirstNode = NULL;
//Used to move along the linked list
Node *pCurrentNode = pFirstNode;
int option = 0;
do
{
DisplayLinkedList( pFirstNode, pCurrentNode );
printf( "\nPlease select an option : " );
printf( "\n0. Exit the program." );
printf( "\n1. Add a node to the end of the list.");
printf( "\n2. Delete the start node from the list.");
printf( "\n3. Delete the end node from the list.");
printf( "\n4. Move the current pointer on one node.");
printf( "\n5. Move the current pointer back one node.\n\n >> ");
scanf_s( "%d", &option );
switch (option)
{
case 1 :
AddNode( pFirstNode, pCurrentNode );
break;
case 2 :
DeleteStartNode( pFirstNode );
break;
case 3 :
DeleteEndNode( pFirstNode );
break;
case 4 :
MoveCurrentNodeForward( pCurrentNode );
break;
case 5 :
MoveCurrentNodeBack( pFirstNode, pCurrentNode );
}
}while( option != 0 );
return 0;
}
void AddNode( Node *pStart, Node *pCurrent )
{
// Temporary pointers
Node *pTemp, *pTempTwo;
// Reserve space for new node and fill it with data
pTemp = new Node;
// User data entry for a new node
printf( "Please enter the age of the person : " );
scanf_s( "%d", &pTemp->age );
printf( "Please enter the height of the person : " );
scanf_s( "%f", &pTemp->height);
pTemp->next = NULL;
// Set up link to this node
if( pStart == NULL )
{
pStart = pTemp;
pCurrent = pStart;
}
else
{
pTempTwo = pStart;
// We know this is not NULL - list not empty!
while ( pTempTwo->next != NULL )
{
pTempTwo = pTempTwo->next;
// Move to next link in chain
}
pTempTwo->next = pTemp;
}
}
I believe you were intending that AddNode() modify pStart and/or pCurrent and actually have main's version of pFirstNode and pCurrentNode be changed by AddNode(), but that is not the case.
Make AddNode take its two pointer parameters by reference.
Yup thats fine, but the inside of the function itself I'm a little confused on how I should be doing it. Because pCurrent = pStart; and **pCurrent = **pStart; both compile for example but I'm not to sure if I should be using one or the other. As the way I have it compiles but it crashes when I user input the age. Debug just tells me age = -87####### so I'm a tad confused :(