/* File: dynlist.C Copyright glh 10/12/82 */ #include "dynlist.H" template DynList::DynList(const DynList& lst) { length = lst.length; size = lst.size; element = new T[size]; for (int i=0; i Boolean DynList::Insert(const T& elm, int pos) { if(pos <= 0 || pos > length) return false; if (length == size) { // load factor is 1 size *= 2; // double the size of the array T* new_array = new T[size]; if (new_array == 0) return false; for (int i=0; i=pos; i--) element[i] = element[i-1]; element[pos-1] = elm; } length++; return true; } template Boolean DynList::Append(const T& elm) { if (length == size) { // load factor is 1 size *= 2; // double the size of the aray T* new_array = new T[size]; if (new_array == 0) return false; for (int i=0; i Boolean DynList::Replace(const T& elm, int pos) { if (pos <= 0 || pos > length) return false; T* new_elm = new T; if (new_elem == 0) return false; *new_elm = elm; element[pos-1] = *new_elm; return true; } template T& DynList::Retrieve(int pos) const { assert((pos > 0) && (pos <= length)); return element[pos-1]; } template Boolean DynList::Delete(int pos) { if (pos <= 0 && pos > length) return false; if (length-1 <= 0.25 * size) { // load factor is <= 1/4 size /= 2; // reduce the size of the array by 1/2 T* new_array = new T[size]; if (new_array == 0) return false; for (int i=0; i 1/4 for (int i=pos; i DynList& DynList::operator=(const DynList& lst) { if (element != lst.element) { // check if list is being assigned to itself delete [] element; // get rid of the old list length = lst.length; size = lst.size; element = new T[size]; for (int i=0; i ostream& operator<<(ostream& os, const DynList& lst) { os << "("; if (lst.Length() != 0) { for (int i=0; i