template<class CircularLinkedListType>
class DataStructures::CircularLinkedList< CircularLinkedListType >
(Circular) Linked List ADT (Doubly Linked Pointer to Node Style) -
By Kevin Jenkins (http://www.rakkar.org) Initilize with the following command LinkedList<TYPE> OR CircularLinkedList<Type>
Has the following member functions
- size: returns number of elements in the linked list
- insert(item): inserts item at the current position in the LinkedList.
- add(item): inserts item after the current position in the LinkedList. Does not increment the position
- replace(item): replaces the element at the current position item.
- peek: returns the element at the current position
- pop: returns the element at the current position and deletes it
- del: deletes the current element. Does nothing for an empty list.
- clear: empties the LinkedList and returns storage
- bool IsInitem): Does a linear search for item. Does not set the position to it, only returns true on item found, false otherwise
- bool find(item): Does a linear search for item and sets the current position to point to it if and only if the item is found. Returns true on item found, false otherwise
- sort: Sorts the elements of the list with a mergesort and sets the current pointer to the first element
- concatenate(list L): This appends L to the current list
- ++(prefix): moves the pointer one element up in the list and returns the appropriate copy of the element in the list
- –(prefix): moves the pointer one element back in the list and returns the appropriate copy of the element in the list
- beginning - moves the pointer to the start of the list. For circular linked lists this is first 'position' created. You should call this after the sort function to read the first value.
- end - moves the pointer to the end of the list. For circular linked lists this is one less than the first 'position' created The assignment and copy constructor operators are defined
- Note
- LinkedList and CircularLinkedList are exactly the same except LinkedList won't let you wrap around the root and lets you jump to two positions relative to the root/
- Postfix ++ and – can be used but simply call the prefix versions.
EXAMPLE:
LinkedList<int> A;
CircularLinkedList<int> B;
A.Insert(20);
A.Insert(5);
A.Insert(1);
A.IsIn1);
A.IsIn200);
A.Find(5);
A.Peek();
A.Find(1);
(++A).Peek();
A.Peek();
A.Replace(10);
A.Peek();
A.Beginning();
(++A).Peek();
A.Peek();
A.Del();
A.Peek();
A.Beginning();
(++A).Peek();
A.Peek();
A.Clear(_FILE_AND_LINE_);
A.Insert(5);
A.Insert(6);
A.Insert(7);
A.Clear(_FILE_AND_LINE_);
B.Clear(_FILE_AND_LINE_);
B.Add(10);
B.Add(20);
B.Add(30);
B.Add(5);
B.Add(2);
B.Add(25);
B.sort();
B.Peek();
B++;
B.Peek();
B++;
B.Peek();
B++;
B.Peek();
B++;
B.Peek();
B++;
B.Peek();