Skip to content

Instantly share code, notes, and snippets.

Created May 28, 2017 23:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/eabf557651abbe56db5aaa4477c3a2c7 to your computer and use it in GitHub Desktop.
Save anonymous/eabf557651abbe56db5aaa4477c3a2c7 to your computer and use it in GitHub Desktop.
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