3
*************************************************************************
5
ArmageTron -- Just another Tron Lightcycle Game in 3D.
6
Copyright (C) 2000 Manuel Moos (manuel@moosnet.de)
8
**************************************************************************
10
This program is free software; you can redistribute it and/or
11
modify it under the terms of the GNU General Public License
12
as published by the Free Software Foundation; either version 2
13
of the License, or (at your option) any later version.
15
This program is distributed in the hope that it will be useful,
16
but WITHOUT ANY WARRANTY; without even the implied warranty of
17
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
GNU General Public License for more details.
20
You should have received a copy of the GNU General Public License
21
along with this program; if not, write to the Free Software
22
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24
***************************************************************************
28
#include "tLinkedList.h"
30
void tListItemBase::Remove(){
34
next->anchor = anchor;
40
void tListItemBase::Insert(tListItemBase *&a){
50
int tListItemBase::Len(){
52
tListItemBase* x=this;
60
void tListItemBase::Sort( Comparator* compare )
62
// early return statements: empty list or single element in list
68
tListItemBase* middle = this;
70
// locate the middle of the list
71
tListItemBase* run = *anchor;
74
middle = middle->next;
83
// split the list in the middle
84
*middle->anchor = NULL;
85
middle->anchor = &middle;
87
// retrieve the anchor of the first half list
88
tListItemBase*& first = *anchor;
90
// sort the two half lists
91
first->Sort( compare );
92
middle->Sort( compare );
96
tListItemBase** run = &first;
99
// find the correct place for middle
100
while ( *run && compare( *run, middle ) > 0 )
103
// remove middle from the second list; care needs to be taken because middle->remove() would modify middle.
104
tListItemBase* insert = middle;
107
// insert it into the first list
108
insert->Insert( *run );