Constructors:
- RNArray
(void); Array Properties:
- const RNBoolean IsEmpty(void) const;
- const int NEntries(void) const;
Entry Properties:
- const int EntryIndex(const RNArrayEntry *entry) const;
- PtrType& EntryContents(RNArrayEntry *entry) const;
Data Access Functions:
- PtrType& Head(void) const;
- PtrType& Tail(void) const;
- PtrType& Kth(int k) const;
- PtrType& operator[](int k) const;
Entry Access Functions:
- RNArrayEntry *HeadEntry(void) const;
- RNArrayEntry *TailEntry(void) const;
- RNArrayEntry *KthEntry(int k) const;
- RNArrayEntry *PrevEntry(const RNArrayEntry *entry) const;
- RNArrayEntry *NextEntry(const RNArrayEntry *entry) const;
- RNArrayEntry *FindEntry(const Type& data) const;
Insertion Functions:
- RNArrayEntry *InsertHead(const PtrType& data);
- RNArrayEntry *InsertTail(const PtrType& data);
- RNArrayEntry *InsertKth(const PtrType& data, int k);
- RNArrayEntry *InsertBefore(const PtrType& data, RNArrayEntry *entry);
- RNArrayEntry *InsertAfter(const PtrType& data, RNArrayEntry *entry);
- RNArrayEntry *Insert(const PtrType& data);
Removal Functions:
- void RemoveHead(void);
- void RemoveTail(void);
- void RemoveKth(int k);
- void RemoveEntry(RNArrayEntry *entry);
- void Remove(const PtrType& data);
Manipulation Functions:
- void Empty(void);
- void Truncate(int length);
- void Shift(int delta);
- void Shift(int start, int length, int delta);
- void Reverse(void);
- void Reverse(int start, int length);
Description:
RNArray<PtrType> is implemented as a templated class that stores entries of a specified pointer data type. The storage allocation for these containers is dynamic -- it expands and contracts as entries are inserted and removed. Once a container has been constructed, entries and the data stored in them can be accessed, rearranged, or modified via member functions or iteration macros. For example, an array of three strings could be constructed and manipulated as follows.
// Construct the array RNArray<char *> array; // Creates an empty array array.Insert("String1"); // Insert the 1st string array.Insert("String2"); // Insert the 2nd string array.Insert("String3"); // Insert the 3rd string // Access entries char *data; data = array.Head(); // data == "String1" data = array.Tail(); // data == "String3" data = array.Kth(0); // data == "String1" data = array.Kth(1); // data == "String2" data = array[1]; // data == "String2" // Access all entries for (int i = 0; i < array.NEntries(); i++) { char *data = array[i]; // or array.Kth(i); printf("%s/n", data); } // Manipulate the array array.RemoveKth(1); // Remove the 2nd entry (first entry is at index 0) array.InsertKth("String2", 1); // Re-insert string in 2nd entryClick this to see a complete sample program.
funk@cs.princeton.edu