Need help with circular doubly linked list code

When I run this in main it gives me a windows error message and I can't figure out whats wrong..please help! I believe it has something to do with my insertAtEnd function but I've gone over it a million times....

#include<iostream>
#include<string>
#include<vector>
#include"RhymeGame.h"

using namespace std;

Game::Game()
{
head = NULL;
current = NULL;
size = 0;
}

Game::Game(const Game& aList)
{
NodePtr fromPtr;
NodePtr toPtr;
if(aList.head == NULL)
{
head = NULL;
return;
}

fromPtr = aList.head;
head = new Node;
head->num = fromPtr->num;
head->word.assign(fromPtr->word);
head->next = head;
head->prev = head;
toPtr = head;
fromPtr = fromPtr->next;
while(fromPtr != aList.head)
{
NodePtr temp = toPtr;
toPtr->next = new Node;
toPtr = toPtr->next;
toPtr->num = fromPtr->num;
toPtr->word.assign(fromPtr->word);
toPtr->prev = temp;
toPtr->next = head;
fromPtr = fromPtr->next;
}
}

Game::~Game()
{
while(head)
{
NodePtr temp = head;
head = head->next;
delete temp;
size--;
}

}

int Game::getSize()
{
return size;
}

int Game::getCurrentNumber()
{
return current->num;
}
void Game::setCurrentNumber(int value)
{
current->num = value;
}

string Game::getCurrentWord()
{
return current->word;
}

void Game::setCurrentWord(string aString)
{
current->word.assign(aString);
}

void Game::printList()
{
if(size == 0)
{
return;
}else if(size == 1)
{
printCurrentNode();
}else
{
current = head;
printCurrentNode();
current = current->next;
while(current != head)
{
printCurrentNode();
current = current->next;
}
}
}
void Game::printReverse()
{
if(size == 0)
{
return;
}else if(size == 1)
{
printCurrentNode();
}else
{
current = head->prev;
printCurrentNode();
current = current->prev;
while(current != head->prev)
{
printCurrentNode();
current = current->prev;
}
}
}

void Game::printCurrentNode()
{
if(size == 0)
{
cout << "-1" << endl;
}else
{
cout << current->num << " " << current->word << endl;
}
}

void Game::insertAtEnd(int value, string a_word)
{
if(size == 0)
{
head = new Node;
head->num = value;
head->word.assign(a_word);
head->prev = head;
head->next = head;
current = head;
size++;

}
else if(size == 1)
{
NodePtr temp = new Node;
temp->num = value;
temp->word.assign(a_word);
temp->next = head;
temp->prev = head;
head->prev = temp;
head->next = temp;
size++;

}else
{
NodePtr temp = new Node;
temp->num = value;
temp->word.assign(a_word);
temp->next = head;
temp->prev = head->prev;
temp->prev->next = temp;
head->prev = temp;
size++;
}

}
void Game::advance()
{
if(size == 0)
{
return;
}else
{
current = current->next;
}
}

void Game::deleteCurrent()
{
if(head == NULL)
{
return;

}else if (current == head && size == 1)
{
head = NULL;
delete current;
current = head;
size--;

}else if(current == head && size == 2)
{
head = head->next;
head->next = head;
head->prev = head;
current = head;
size--;

}else if(current == head && size > 2)
{
head= head->next;
current->prev->next = head;
head->prev = current->prev;
delete current;
current = current->next;
size--;
}else
{
current->prev->next = current->next;
current->next->prev = current->prev;
delete current;
current = current->next;
}

}
void Game::eraseList()
{
while(size != 0)
{
NodePtr temp = head;
head = head->next;
delete temp;
size--;
}
}
void Game::operator =(const Game& aList)
{
NodePtr fromPtr;
NodePtr toPtr;
if(aList.head == head )
{
return;
}
if(aList.head == NULL)
{
head = NULL;
return;
}

fromPtr = aList.head;
head = new Node;
head->num = fromPtr->num;
head->word.assign(fromPtr->word);
head->next = head;
head->prev = head;
toPtr = head;
fromPtr = fromPtr->next;
while(fromPtr != aList.head)
{
NodePtr temp = toPtr;
toPtr->next = new Node;
toPtr = toPtr->next;
toPtr->num = fromPtr->num;
toPtr->word.assign(fromPtr->word);
toPtr->prev = temp;
toPtr->next = head;
fromPtr = fromPtr->next;
}
}
I will link you to ne555 thread: http://www.cplusplus.com/forum/general/112111/
What errror message? Is it compile or runtime? What did you did to localize place of error? Can you provide isolated test case?

Also use code tags: they looks like <> on the right of post edit field.
Last edited on
I am willing to help you but, would you please write some notes for it? If not, it's hard to find what is wrong. Both others and I don't want to read such a long code, especially with no notes.
@csullsun:write your code using [code] [/code] when your posting.
Last edited on
Topic archived. No new replies allowed.