fixed size() function, added empty() function

This commit is contained in:
Pavol Marko 2004-03-24 18:34:47 +00:00
parent ab110d3d27
commit a9a46e20b2

View File

@ -51,21 +51,28 @@ public:
}; };
private: private:
CListEle *head; CListEle *head;
int cur_size;
public: public:
CList<T,F>() { head = 0; cur_size = 0; } CList<T,F>() { head = 0; }
~CList<T,F>() { clear(); } ~CList<T,F>() { clear(); }
void clear() { void clear() {
iterator a = begin(); iterator a = begin();
while( a ) a.remove(); while( a ) a.remove();
cur_size = 0; }
bool empty() {
return (head ? false : true);
} }
void put( T* a ) { void put( T* a ) {
head = new CListEle( a , head ); head = new CListEle( a , head );
++cur_size;
} }
int size() { int size() {
return cur_size; CListEle *p = head;
int i = 0;
while (p)
{
p = p->next;
++i;
}
return i;
} }
class iterator { class iterator {
CListEle** a; CListEle** a;