Error inserting word into Linked List
So I have my Linked List struct here
struct ListNode
{
string item;
ListNode *next;
};
ListNode *head;
ListNode *cur;
ListNode *prev;
ListNode *search();
And my method to add nodes into Linked List
inline void List::guessedWords( string guess )
{
cur = head;
while ( cur != NULL )
{
ListNode *newNode = new ListNode;
newNode->item = guess;
if ( head == NULL )
{
newNode->next = NULL;
head = newNode;
}
else
{
prev = search();
newNode->next = cur;
prev->next = newNode;
}
cur = newNode;
}
}
Anyone can point to my what's my mistakes? I couldn't get to add the first
node.
Search function is to traverse to the end of node. What I'm trying to do
is to keep on adding words into the back of he node.
No comments:
Post a Comment