/* Simple list type to hold arbitrary (see comments) quantity of objects. Accessible by array notation ([]) Maintains own size Warren Myers Sep 2004 WMM Jun 05 - updated handling of bogus indices into the array.. see the operator [] code WMM Oct 05 - added destructor This source is in the public domain. The original author does not make any claims as to usefulness, correctness, or suitability of this code for any purpose. Changes may be made at will and released, just keep this header in any derivative work. Interface definition: arrlist arrlist al; // 10000 size int array arrlist cl; // 210 size char array void empty() - reset size to empty list void clear() - reset size and reset every element to blank void clear(int pos) - like clear(), but only after pos int max() - most items you can hold in list int size() - current last location of stored item (0 based like normal C arrays) bool add(T next) - if there's room, insert next at end of list bool remove(int pos, T &res) - if exists, copy item at pos into res, then slide entire list afterward up one spot, update size bool remove(int pos) - if exists, move end item into position pos, update size */ #ifndef _ARRLIST_H_ #define _ARRLIST_H_ template class arrlist{ T blank, dummy; T items[(SIZE+1)]; int len; bool ok; bool valid(int p){ if(p=SIZE) return false; return true; } public: arrlist(){ empty(); } arrlist(int s, T l[]){ if(s>SIZE) s=SIZE; if(s<1) return; int k = 0; while(k0){ pos %= SIZE; // adjust for values too big } else{ pos = -pos; // this indexes from end instead of from start, is a negative index pos %= SIZE; pos = SIZE-pos; } if(pos>len){ len = pos+1; } return items[pos]; } bool add(T next){ if(SIZE == len) return false; len++; items[len] = next; return true; } bool remove(int pos, T &res){ // expensive call due to sliding contents up the list if((ok = valid(pos))){ res = items[pos]; int k = pos; while(k