quick start:g++ [flags ...] file ... #include <DoubleLinkedList.h> DoubleLinkedList(ALLOCATION alloc_d = DEF_ALLOCATION); boolean insert(TObject* item); boolean insertFirst(TObject* item); boolean removeLast(TObject*& item); const TObject* getPrev() const;
description:// declare a character list and add two characters into it // DoubleLinkedList<Char> list; Char item0(L'a'); Char item1(L'b'); list.insertFirst(&item0); list.insert(&item1); // get the last character // list.gotoLast(); Char* item2 = list.getCurr(); if (item2->ne(item1)) { // error }
static const String CLASS_NAME = L"DoubleLinkedList";
static const String DEF_PARAM = L"values";
static const long ERR = 40400;
typedef DoubleLinkedNode<TObject> NODE;
NODE* first_d;
NODE* last_d;
NODE* curr_d;
NODE* mark_d;
Long length_d;
ALLOCATION alloc_d;
static Integral::DEBUG debug_level_d;
static MemoryManager mgr_d;
static const String& name();
static boolean diagnose(Integral::DEBUG debug_level);
static boolean setDebug(Integral::DEBUG debug_level);
boolean debug(const unichar* message) const;
~DoubleLinkedList();
DoubleLinkedList(ALLOCATION alloc = DEF_ALLOCATION);
DoubleLinkedList(const DoubleLinkedList<TObject>& copy_list);
boolean assign(const DoubleLinkedList<TObject>& copy_list);
DoubleLinkedList<TObject>& operator=(const DoubleLinkedList<TObject>& arg);
boolean eq(const DoubleLinkedList<TObject>& compare_list) const;
long sofSize() const;
boolean read(Sof& sof, long tag);
boolean write(Sof& sof, long tag) const;
boolean read(Sof& sof, long tag, const String& name);
boolean write(Sof& sof, long tag, const String& name) const;
boolean readData(Sof& sof, const String& pname = DEF_PARAM, long size = SofParser::FULL_OBJECT, boolean param_a = true, boolean nested_a = false);
boolean writeData(Sof& sof, const String& pname = DEF_PARAM) const;
static void* operator new(size_t size);
static void* operator new[](size_t size);
static void operator delete(void* ptr);
static void operator delete[](void* ptr);
static boolean setGrowSize(long grow_size);
boolean clear(Integral::CMODE cmode = Integral::DEF_CMODE);
TObject& operator() (long index);
const TObject& operator() (long index) const;
boolean ne(const DoubleLinkedList<TObject>& compare_list) const;
boolean gotoFirst();
boolean gotoLast();
boolean gotoNext();
boolean gotoPrev();
boolean gotoMark();
boolean gotoPosition(long number);
long getPosition() const;
boolean markIsSet() const;
boolean isMarkedElement() const;
boolean clearMark() const;
boolean setMark() const;
TObject* getFirst();
const TObject* getFirst() const;
TObject* getLast();
const TObject* getLast() const;
TObject* getNext();
const TObject* getNext() const;
TObject* getPrev();
const TObject* getPrev() const;
TObject* getMark();
const TObject* getMark() const;
TObject* getCurr();
const TObject* getCurr() const;
boolean insert(TObject* item);
boolean insert(DoubleLinkedList<TObject>& ilist);
boolean remove(TObject*& item);
boolean remove();
boolean insertFirst(TObject* item);
boolean insertFirst(DoubleLinkedList<TObject>& ilist);
boolean removeFirst(TObject*& item);
boolean removeFirst();
boolean insertLast(DoubleLinkedList<TObject>& ilist);
boolean removeLast(TObject*& item);
boolean removeLast();
boolean isEmpty() const;
boolean isFirst() const;
boolean isLast() const;
long length() const;
boolean find(const TObject* item);
boolean contains(const TObject* item) const;
boolean sort(Integral::ORDER sort_order = Integral::ASCENDING, SORT_ALGO = DEF_SORT_ALGO);
boolean reverse();
boolean swap(long i, long j);
boolean apply(boolean (TObject::*method)());
boolean apply(boolean (TObject::*method)(), DoubleLinkedList<TObject>& arg);
ALLOCATION getAllocationMode() const;
boolean setAllocationMode(ALLOCATION alloc);
boolean randQuickSort(Integral::ORDER sort_order);
boolean insertionSort(Integral::ORDER sort_order);
boolean swap(NODE*& i_node, NODE*& j_node);
NODE* getNode(long index) const;
friend class DoubleLinkedListDiagnose;examples:
#include <DoubleLinkedList.h> #include <Char.h> int main() { // local variables // DoubleLinkedList<Long> d; Long j; // add 10 items to the DoubleLinkedList // for (long i = 0; i< 10; i++) { j = i * 3; d.insert(&j); } // see what is on the DoubleLinkedList // d.debug(L"after insertion"); // get the elements and print them // d.gotoFirst(); Long* l = d.getFirst(); l->debug(L"item from the List"); while((l=d.getNext())!=NULL) { d.gotoNext(); l->debug(L"item from the List"); } // exit gracefully // Integral::exit(); }
#include <DoubleLinkedList.h> #include <Char.h> int main() { // local variables // DoubleLinkedList<long> d(USER); Long* j; // add 10 items to the DoubleLinkedList // for (long i = 0; i< 10; i++) { j = new Long(i * 3); d.insert(j); } // see what is on the DoubleLinkedList // d.debug(L"after insertion"); // get the elements and print them // d.gotoFirst(); Long* l = d.getFirst(); l->debug(L"item from the List"); delete l; while((l=d.getNext())!=NULL) { d.gotoNext(); l->debug(L"item from the List"); delete l; } // exit gracefully // Integral::exit(); }
#include <DoubleLinkedList.h> #include <Char.h> int main() { // prepare items for the list // Char** items = new Char*[10]; // declare a SYSTEM-allocating DoubleLinkedList and insert items into it // DoubleLinkedList<Char> char_list; for (long i = 0; i < 10; i++) { items[i] = new Char((unichar)((long)'a' + i)); // insert the items to the list // char_list.insert(items[i]); } // copy the DoubleLinkedList // DoubleLinkedList<Char> char_copy_list(char_list); // declare a third list that is SYSTEM-allocating, and has the same items // DoubleLinkedList<Char>* system_char_list = new DoubleLinkedList<Char>(); system_char_list->assign(char_list); // see if these DoubleLinkedLists are equivalent // if(!char_list.eq(char_copy_list) || !system_char_list->eq(char_list)) { // exit with error // Integral::exit(); } // clean up the memory used // delete system_char_list; delete [] items; // exit gracefully // Integral::exit(); }