2 * A generic template list class.
3 * Fairly typical of the list example you would
4 * find in any c++ book.
12 template <class Type
> class List
{
27 Type
&operator[](int i
){assert(i
>=0 && i
<num
); return element
[i
];}
32 List
<Type
>::List(int s
){
47 void List
<Type
>::allocate(int s
){
52 element
= new Type
[array_size
];
54 for(int i
=0;i
<num
;i
++){
60 void List
<Type
>::SetSize(int s
){
61 if(s
==0) { if(element
) delete element
;}
66 void List
<Type
>::Pack(){
71 void List
<Type
>::Add(Type t
){
72 assert(num
<=array_size
);
74 allocate((array_size
)?array_size
*2:16);
77 //for(i=0;i<num;i++) {
78 // dissallow duplicates
79 // assert(element[i] != t);
85 int List
<Type
>::Contains(Type t
){
89 if(element
[i
] == t
) count
++;
95 void List
<Type
>::AddUnique(Type t
){
96 if(!Contains(t
)) Add(t
);
100 template <class Type
>
101 void List
<Type
>::DelIndex(int i
){
105 element
[i
] = element
[i
+1];
110 template <class Type
>
111 void List
<Type
>::Remove(Type t
){
114 if(element
[i
] == t
) {
120 assert(element
[i
] != t
);