2
* libpal - Automated Placement of Labels Library
4
* Copyright (C) 2008 Maxence Laurent, MIS-TIC, HEIG-VD
5
* University of Applied Sciences, Western Switzerland
9
* maxence.laurent <at> heig-vd <dot> ch
11
* eric.taillard <at> heig-vd <dot> ch
13
* This file is part of libpal.
15
* libpal is free software: you can redistribute it and/or modify
16
* it under the terms of the GNU General Public License as published by
17
* the Free Software Foundation, either version 3 of the License, or
18
* (at your option) any later version.
20
* libpal is distributed in the hope that it will be useful,
21
* but WITHOUT ANY WARRANTY; without even the implied warranty of
22
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
* GNU General Public License for more details.
25
* You should have received a copy of the GNU General Public License
26
* along with libpal. If not, see <http://www.gnu.org/licenses/>.
34
#ifndef _LINKED_LIST_H
35
#define _LINKED_LIST_H
45
* \brief Generic cell for LinkedList
46
* \param Type Generic class
52
/** \brief Create a new Cell
53
* \param item The object to store
55
Cell( Type item ) : item( item ), next( NULL ) {};
61
* \brief Generic queue
62
* \param Type generic class
76
bool ( *compare )( Type a, Type b );
81
* \brief Create a new empty list
83
LinkedList( bool ( *compare )( Type a, Type b ) ) : first( NULL ), last( NULL ), s( 0 ), compare( compare ) {};
85
* \brief delete the list
89
//void setCompareMethod (bool (*compare)(Type a, Type b));
92
* \brief is item into list ?
93
* \return true or false
95
bool isIn( Type item );
98
* \brief Insert an item at the end
99
* \param item The item to insert
101
void push_back( Type item );
104
* \brief Insert an item in first position
105
* \param item The item to insert
107
void push_front( Type item );
110
* \brief extract and return the last item
111
* \return Extracted item
116
* \brief get the list size
117
* \return the number of item into the queue
122
* \brief get the first cell
123
* \return the first elem, as iterator
125
Cell<Type> *getFirst();
127
Cell<Type> *search( Type item );
129
void remove( Type item );
136
template <class Type>
137
LinkedList<Type>::~LinkedList()
152
template <class Type>void LinkedList<Type>::push_back( Type item )
156
first = new Cell<Type> ( item );
161
last->next = new Cell<Type> ( item );
167
template <class Type>void LinkedList<Type>::push_front( Type item )
169
Cell<Type> *n = new Cell<Type> ( item );
176
template<class Type>Type LinkedList<Type>::pop_front()
195
template <class Type>bool LinkedList<Type>::isIn( Type item )
197
Cell<Type> *cur = first;
201
if ( item == cur->item )
209
template <class Type>int LinkedList<Type>::size()
215
template <class Type>Cell<Type> *LinkedList<Type>::getFirst()
221
template <class Type> void LinkedList<Type>::remove( Type item )
223
Cell<Type> *p = first;
228
if ( compare( item, p->item ) )
235
while ( p->next && !compare( p->next->item, item ) ) {p = p->next;}
249
template <class Type> Cell<Type> * LinkedList<Type>::search( Type item )
251
Cell<Type> *p = first;
253
while ( p && !compare( p->item, item ) )
262
/*template <class Type> void LinkedList<Type>::setCompareMethod (bool (*compare)(Type a, Type b)){
263
this->compare = compare;
266
template <class Type> void LinkedList<Type>::clean()
268
Cell<Type> *it = first;