コード例 #1
0
    private void addToQueue(Character c)
    {
        if (battleQueue == null)
        {
            battleQueue = new CharacterNode(c, battleQueue);
            battleQueue.setNextRef(battleQueue);
        }
        else
        {
            CharacterNode current = battleQueue;

            //keep traversing as long as c.speed is greater than the one next to it and
            //the next node is not the head node
            while (c.speed >= current.getCharacterRef().speed&& !battleQueue.equals(current.getNext()))
            {
                current = current.getNext();
            }

            current.setNextRef(new CharacterNode(c, current.getNext()));
        }
    }