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
){
28 assert(i
>=0 && i
<num
);
34 List
<Type
>::List(int s
){
49 void List
<Type
>::allocate(int s
){
54 element
= new Type
[array_size
];
56 for(int i
=0;i
<num
;i
++){
62 void List
<Type
>::SetSize(int s
){
63 if(s
==0) { if(element
) delete element
;}
68 void List
<Type
>::Pack(){
73 void List
<Type
>::Add(Type t
){
74 assert(num
<=array_size
);
76 allocate((array_size
)?array_size
*2:16);
79 //for(i=0;i<num;i++) {
80 // dissallow duplicates
81 // assert(element[i] != t);
87 int List
<Type
>::Contains(Type t
){
91 if(element
[i
] == t
) count
++;
97 void List
<Type
>::AddUnique(Type t
){
98 if(!Contains(t
)) Add(t
);
102 template <class Type
>
103 void List
<Type
>::DelIndex(int i
){
107 element
[i
] = element
[i
+1];
112 template <class Type
>
113 void List
<Type
>::Remove(Type t
){
116 if(element
[i
] == t
) {
122 assert(element
[i
] != t
);