Created
May 28, 2017 23:27
-
-
Save anonymous/eabf557651abbe56db5aaa4477c3a2c7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct ListNode | |
{ | |
double value; | |
ListNode *next; | |
}; | |
ListNode *head; | |
void NumberList::appendNode(double num) | |
{ | |
ListNode *newNode; //to point to a new node | |
ListNode *nodePtr; // to move through the list | |
//allocate a new node and store num there | |
newNode = new ListNode; | |
newNode->value = num; | |
newNode->next = nullptr; | |
//if there are are no nodes in the list make newNode the first | |
if (!head) | |
head = newNode; | |
else // otherwise, insert NewNode at the end | |
{ | |
//initialize nodePtr to head of list | |
nodePtr = head; | |
//find the last node in the list. | |
while (nodePtr->next) | |
nodePrt = nodePtr->next; | |
//insert newNode as the last node | |
nodePtr->next = newNode; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment