4 // designed for lists of track numbers
13 TYPE
append(TYPE value
);
15 TYPE
insert(TYPE value
, int number
);
18 void allocate(int total
);
19 // remove last pointer from end
21 // remove last pointer and object from end
23 // remove pointer to object from list
24 void remove(TYPE value
);
25 // remove object and pointer to it from list
26 void remove_object(TYPE value
);
27 // remove object and pointer to it from list
28 void remove_object_number(int number
);
29 // remove pointer to item numbered
30 void remove_number(int number
);
31 // Return number of first object matching argument
32 int number_of(TYPE object
);
34 // Remove pointer and objects for each array entry
35 void remove_all_objects();
37 void set_array_delete();
50 ArrayList
<TYPE
>::ArrayList()
55 values
= new TYPE
[available
];
60 ArrayList
<TYPE
>::~ArrayList()
62 // Just remove the pointer
67 void ArrayList
<TYPE
>::set_array_delete()
74 void ArrayList
<TYPE
>::allocate(int total
)
79 TYPE
* newvalues
= new TYPE
[available
];
80 for(int i
= 0; i
< total
; i
++) newvalues
[i
] = values
[i
];
87 TYPE ArrayList
<TYPE
>::append(TYPE value
) // add to end of list
89 if(total
+ 1 > available
)
92 TYPE
* newvalues
= new TYPE
[available
];
93 for(int i
= 0; i
< total
; i
++) newvalues
[i
] = values
[i
];
98 values
[total
++] = value
;
103 TYPE ArrayList
<TYPE
>::append() // add to end of list
105 if(total
+ 1 > available
)
108 TYPE
* newvalues
= new TYPE
[available
];
109 for(int i
= 0; i
< total
; i
++) newvalues
[i
] = values
[i
];
115 return values
[total
- 1];
119 TYPE ArrayList
<TYPE
>::insert(TYPE value
, int number
)
122 for(int i
= total
- 1; i
> number
; i
--)
124 values
[i
] = values
[i
- 1];
126 values
[number
] = value
;
130 void ArrayList
<TYPE
>::remove(TYPE value
) // remove value from anywhere in list
134 for(in
= 0, out
= 0; in
< total
;)
136 if(values
[in
] != value
) values
[out
++] = values
[in
++];
146 TYPE ArrayList
<TYPE
>::last() // last element in list
148 return values
[total
- 1];
154 void ArrayList
<TYPE
>::remove_object(TYPE value
) // remove value from anywhere in list
164 void ArrayList
<TYPE
>::remove_object_number(int number
)
169 delete [] values
[number
];
171 delete values
[number
];
172 remove_number(number
);
175 fprintf(stderr
, "ArrayList<TYPE>::remove_object_number: number %d out of range %s.\n", number
, total
);
180 void ArrayList
<TYPE
>::remove_object() // remove value from anywhere in list
185 delete [] values
[total
- 1];
187 delete values
[total
- 1];
191 fprintf(stderr
, "ArrayList<TYPE>::remove_object: array is 0 length.\n");
197 void ArrayList
<TYPE
>::remove()
202 // remove pointer from anywhere in list
204 void ArrayList
<TYPE
>::remove_number(int number
)
207 for(in
= 0, out
= 0; in
< total
;)
210 values
[out
++] = values
[in
++];
212 // need to delete it here
219 void ArrayList
<TYPE
>::remove_all_objects()
221 //printf("ArrayList<TYPE>::remove_all_objects 1 %d\n", total);
222 for(int i
= 0; i
< total
; i
++)
233 void ArrayList
<TYPE
>::remove_all()
238 // sort from least to greatest value
240 void ArrayList
<TYPE
>::sort()
248 for(int i
= 0, j
= 1; j
< total
; i
++, j
++)
250 if(values
[j
] < values
[i
])
253 values
[i
] = values
[j
];
262 int ArrayList
<TYPE
>::number_of(TYPE object
)
264 for(int i
= 0; i
< total
; i
++)
266 if(values
[i
] == object
) return i
;