quick start:g++ [flags ...] file ... #include <SingleLinkedList.h> SingleLinkedList(ALLOCATION alloc_d = DEF_ALLOCATION) ; boolean insert(TObject* item, boolean insert_before); boolean insertFirst(TObject* item); boolean removeLast(); const TObject* getNext() const; boolean apply(boolean (TObject::*method)());
description:// declare a character list and add two characters into it // SingleLinkedList<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 SysString CLASS_NAME = L"SingleLinkedList";
static const SysString DEF_PARAM = L"values";
static const long ERR = 40300;
typedef SingleLinkedNodeNODE;
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;
~SingleLinkedList();
SingleLinkedList(ALLOCATION alloc = DEF_ALLOCATION);
SingleLinkedList(const SingleLinkedList<TObject>& copy_list);
boolean assign(const SingleLinkedList<TObject>& copy_list);
SingleLinkedList<TObject>& operator=(const SingleLinkedList<TObject>& arg);
boolean eq(const SingleLinkedList<TObject>& compare_list) const;
long sofSize() const;
boolean read(Sof& sof_a, long tag_a);
boolean write(Sof& sof_a, long tag_a) const;
boolean read(Sof& sof_a, long tag_a, const String& name_a);
boolean write(Sof& sof_a, long tag_a, const String& name_a) 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 SingleLinkedList<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();
boolean setMark();
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_before);
boolean insert(SingleLinkedList& ilist);
boolean remove(TObject*& item);
boolean remove();
boolean insertFirst(TObject* item);
boolean insertFirst(SingleLinkedList& ilist);
boolean removeFirst(TObject*& item);
boolean removeFirst();
boolean insertLast(TObject* item);
boolean insertLast(SingleLinkedList& 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(TObject* value);
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)(), SingleLinkedList<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*& j);
NODE* getNode(long index) const;
NODE* getPrevNode(NODE* node) const;
friend class SingleLinkedListDiagnose;examples:
#include <SingleLinkedList.h> #include <Char.h> int main() { // local variables // SingleLinkedList<Long> s; Long j; // add 10 items to the SingleLinkedList // for (long i = 0; i< 10; i++) { j = i * 3; s.insert(&j); } // see what is on the SingleLinkedList // s.debug(L"after insertion"); // get the elements and print them // s.gotoFirst(); Long* l = s.getFirst(); l->debug(L"item from the List"); while((l= s.getNext())!=NULL) { s.gotoNext(); l->debug(L"item from the List"); } // exit gracefully // Integral::exit(); }
#include <SingleLinkedList.h> #include <Char.h> int main() { // local variables // SingleLinkedList<Long> s(USER); Long* j; // add 10 items to the SingleLinkedList // for (long i = 0; i< 10; i++) { j = new Long(i * 3); s.insert(j); } // see what is on the SingleLinkedList // s.debug(L"after insertion"); // get the elements and print them // s.gotoFirst(); Long* l = s.getFirst(); l->debug(L"item from the List"); delete l; while((l=s.getNext())!=NULL) { s.gotoNext(); l->debug(L"item from the List"); delete l; } // exit gracefully // Integral::exit(); }
#include <SingleLinkedList.h> #include <Char.h> int main() { // prepare items for the list // Char** items = new Char*[10]; // declare a SYSTEM-allocating SingleLinkedList and add items into it // SingleLinkedList<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 SingleLinkedList // SingleLinkedList<Char> char_copy_list(char_list); // declare a third list that is SYSTEM-allocating, and has the same items // SingleLinkedList<Char>* system_char_list = new SingleLinkedList<Char>(); system_char_list->assign(char_list); // see if these SingleLinkedLists 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(); }