I need to check and see if my value inside my node is '\0'. Every time I run the program I get stuck in my while loop when I add more than one character. How can I check the data inside my node?
//adds character to the back of the circular linked list
void LinkedList::addBack(char data)
{
if (head == NULL) {
head = new ListNode(data);
back = head;
head->next = head;
}
else
{
ListNode *newNode = new ListNode(data);
this->back = newNode;
this->head->next = newNode;
newNode->next = head;
}
}
//removes the first character and sets to null
char LinkedList::removeFirst()
{
char temp= '\0';
// If the list is empty, do nothing
if (head != NULL) {
temp = head->data; //temp is set to data in first node
head->data = '\0'; //head is data is set to null leaving it empty
head = head->next; // head is set to next node
}
return temp; //returned to display
}
void LinkedList::displayFirst()
{
ListNode *nodePtr = head; // Start at head of list
while (nodePtr->next->data != '\0') { //loops through displaying the first node character, until head is NULL again
// Print the value in the first node
cout << removeFirst();
nodePtr = nodePtr->next; //moves onto the next node to display and remove
}
}