-1
bool CharacterList::addCharacter(Character *newCharacter)
{
    Character *temp, *back;

    if(head == NULL)
    {
        head = newCharacter;
    }

    else
    {
        temp = head;
        back = NULL;
        while((temp != NULL) &&  (temp < newCharacter))
        {
            back = temp;
            temp = temp.next;
        }

        if(back == NULL)
        {
            newCharacter.next = head;
            head = newCharacter;
        }

        else
        {
            back.next = newCharacter;
            newCharacter.next = temp;
        }

        return true;
    }

}

I'm creating an ordered linked list(CharacterList) for the objects of class Character. This function will take only one argument, a pointer to a Character class object(*newCharacter). It will then add this character to the linked list of character objects. I'm not sure if this is how I insert an object to the linked list. can someone guide me please ?

Max Smith
  • 13
  • 2
  • 4
  • 4
    Stack Overflow is not for "guiding" or "mentoring". It is for concrete questions about programming languages. For learning the basics of the language, please study your C++ book in _detail_ and consult the documentation. Thank you. – Lightness Races in Orbit Mar 29 '14 at 03:05
  • With all due respect, when I asked for "guiding" I meant to ask for help with the above code. I'm not sure if I'm using "<" properly to compare the objects in the linked list. As well as I wanted to make sure all my declarations look correct. Compiler is not even attempting to compile the code above. Thanks! – Max Smith Mar 29 '14 at 03:10
  • 1
    With all due respect back at you, you have high expectations of a group of people offering their time for free. You are expected to put in some of your own time and effort in learning the technologies that you want to use. There is no indication here that you have hit a technical roadblock in your learning, only that you have stopped doing it for some reason. Certainly it is interesting that you have not even once mentioned "the compiler is not even attempting to compile the code" in your question. – Lightness Races in Orbit Mar 29 '14 at 03:12
  • I apologize that I didn't mention about the compiler issue. I understand that the help I'm getting is free and I'm really thankful for that. And if I've wasted your time then I apologize for that too! – Max Smith Mar 29 '14 at 03:18
  • I'm sorry I didn't understand what you were trying to say. I'm not that tech savvy. – Max Smith Mar 29 '14 at 03:22

1 Answers1

3

Instead of reinventing your own, you should use std::list, as follows:

std::list<Character> CharacterList;

But please read a good book before going any further.

Community
  • 1
  • 1
Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055