Single Linked List
template <typename Key, typename Info>
class Sequence {
struct Node {
Key key;
Info info;
Node next;
}
Node *head;
public:
Sequence();
~Sequence();
Sequence(const Sequence<Key, Info>& seq);
int getSize() const;
void clear() const;
int find(const Key&);
void pushBack(const Key&, const Info&);
void pushFront(const Key&, const Info&);
bool popFront();
bool popEnd();
void replace(Key key, const Info&, int instance = 1);
void replaceAll(Key key, Info info);
bool insertBefore(const Key&, const Info&, Key key, int = 1);
bool insertAfter(const Key&, const Info&, Key key, int = 1);
bool insertAfter(Key newKey, Info info, Key key, int = 1);
bool remove(const Key&, int = 1);
int removeAll(const Key&); // how many instances we removed
bool removeAfter(Key key);
bool isEmpty();
bool hasKey(Key key);
bool hasInfo(Info info);
void concatStart(Sequence<Key, Info>& seq);
void concatEnd(Sequence<Key, Info>& seq);
void sort();
void reverse();
void swap(Sequence<Key, Info>&);
Sequence<Key, Info>& subSeqFrom(const Key&, int = 1) const;
Sequence<Key, Info>& subSeqTo(const Key&, int = 1) const;
Sequence<Key, Info>& subSeqBetween(const Key& start, int S, const Key& end, int E);
Sequence<Key, Info)& operator= (const Sequence<Key, Info>&)
Sequence<Key, Info> operator+ (const Sequence<Key, Info>&);
bool operator == (const Sequence<Key, Info>& seq)
bool operator != (const Sequence<Key, Info>& seq)
Info getInfo(Key key, int = 1);
// this is a bad function, because what it will return if there is no matching key?
// we have to use a trick
bool getInfo(Info& result, count Key&, int = 1);
// if info is found, function will return 1 and our wanted info will be in 'result'. If not, return is 0 and result is NULL
}
if {cpp}struct Node appears in private part of class, we cannot create public functions with it.
A must for each class is
- Constructor
- Copy constructor
- Destructor
- Assignment operator
First lab
create a single linked list class
according to the given resources and wanted result
2 weeks for implementing the task e