// // Basic Summary: clasical list implementation // // Implementation file for list definition // // Copyright: // // Copyright 1993 Ron Burback // Copyright 1993 Objects Plus // All rights reserved // // Description: // // Include files: // #include #include "standard.h" #include "list.h" // // define the version of this structure // char * list::version = "Objects Plus List Version 1.0" ; // // function: list // parameters: none // goal: basic constructor // returns: new element // list::list() {} // // function: ~list // parameters: none // goal: basic destructor // returns: element to the heap // list::~list() {} // // function: first // parameters: none // goal: get the first element without effecting the list // returns: the first element // void * list::first() { return peak(0); } // // function: rest // parameters: none // goal: remove the first element and return the list with one less element // returns: a new list, the first element is discarded // void list::rest() { void * l = get(0); } // // function: append // parameters: a second list // goal: append a list to the end of this list // returns: the same list but now with the added elements from the second list // void list::append( list * l) { natural l1 = length(); natural l2 = l->length(); for(natural i=0;ipeak(i));}; } // // function: reverse // parameters: none // goal: reverse the order of a list // returns: same list but in a reversed order // void list::reverse () { natural l = length() ; dynamic_array * d = new dynamic_array() ; for(natural i=0;iset(0,get(0));} // now gut the old data structures are replace with the new gut(d) ; delete d ; }; // // function: QA test // parameters: none // goal: self test of list, should return true, with no memory creap // returns: true/false // Boolean list::test() { Boolean results = true ; natural limit = 200 ; list * l ; list * m ; // store a bunch of unique numbers l = new list(); for(int i=0;i<=limit;i++){ l->set(i,(void *)i); } // verify the list works for(i=0;i<=limit;i++){ results &= (void *)i == l->first(); l->rest(); } delete l ; // make sure reverse works l = new list(); for(i=0;i<=limit;i++){l->set(i,(void *)i); } l->reverse(); for(i=limit;i>=0;i--) { results &= ((void *)i == l->first()); l->rest(); } delete l ; //make sure append works l = new list(); for(i=0;i<=limit;i++){l->set(i,(void *)i); } m = new list(); for(i=limit+1;i<=2*limit;i++){m->set(i-limit-1,(void *)i); } l->append(m); for(i=0;i<=2*limit;i++){ results &= ((void *)i == l->first()); l->rest(); } delete l; delete m; // done return results ; }