43 lines
1.5 KiB
C++
Executable File
43 lines
1.5 KiB
C++
Executable File
#ifndef __TLL_H
|
|
#define __TLL_H
|
|
|
|
// tll.h
|
|
|
|
/* this implements a template class linklist, descended from tlist.h
|
|
one can create an assoc array out of this by creating an elem class in
|
|
which the comparison operator depends on the key alone. Then search will
|
|
return the full elem and one can check the associated vaule to the key
|
|
*/
|
|
|
|
#include <iostream.h>
|
|
#include "tlist.h"
|
|
|
|
|
|
template <class Elem> class LLNode;
|
|
template <class Elem> class LinkedList : public List<Elem> {
|
|
LLNode<Elem> *root;
|
|
public:
|
|
LinkedList(void);
|
|
~LinkedList(void);
|
|
LinkedList(const LinkedList<Elem> &llist); // the copy constructor
|
|
LinkedList &operator = (const LinkedList<Elem> &llist);
|
|
Elem *Insert(const Elem &elem); // this does not insert if val already exists
|
|
// returns ptr to elem in list if it could insert
|
|
void Clear(void);
|
|
int DeleteNext(Elem &elem); // deletes first elem in list and returns it
|
|
int GetNext(Elem &elem, int start); // returns the next element in the list, if start is set then returns
|
|
// the first one, returns 0 if the list is now empty
|
|
Elem *Search(const Elem &elem); // assumes the == operator defined on elem
|
|
void Write(ostream &s);
|
|
friend ostream &operator<<(ostream &s, LinkedList<Elem> &ll);
|
|
int Empty(void) {return (root ? 0 : 1);}
|
|
int Size(void) {return length;}
|
|
private:
|
|
int length;
|
|
LLNode<Elem> *get_next_ptr; // because the next one is ongoing
|
|
|
|
};
|
|
|
|
#endif
|
|
|