Napisz klasę wzorcową sll definiującą listę jednokierunkową
elementów zadanego typu oraz pomocniczą strukturę Node. Poniżej
przedstawiono schemat obu struktur do uzupełnienia.
template <typename T>
struct Node {
T data;
Node* next;
Node(T data, Node* next);
};
template <typename T>
class sll {
public:
sll();
~sll();
T front(); // access the first element
T back(); // access the last element
void pushFront(T data); // inserts an element to the beginning
void pushBack(T data); // adds an element to the end
void popFront(); // removes the first element
void popBack(); // removes the last element
ostream& print(ostream&) const; // print all elements of the list
private:
Node<T>* head;
Node<T>* tail;
};
Napisz operator strumieniowy (<<), drukujący listę i
wykorzystujący funcję print(). Funkcja main() powinna
testować działanie listy dla wybranych typów (wbudowanych i własnych).
Napisz klasę wzorcową CyclicBuffer reprezentującą bufor
cykliczny o typie elementu zadanym pierwszym parametrem wzorca i liczbie
elementów zadanej drugim parametrem. Proponowany schemat klasy:
template<typename T, int CAPACITY = 8>
class CyclicBuffer {
public:
CyclicBuffer();
bool empty() const; // check if empty
bool full() const; // check if full
T get(); // get an element from buffer, throw an exception if empty
void put(T value); // put value to buffer, throw an exception if full
ostream& print(ostream&) const; // print buffer
private:
T buffer[CAPACITY];
int p_read; // index to read
int p_write; // index to write
int count; // number of elements
};
Napisz funkcję main() pokazującą działanie klasy dla bufora
liczb całkowitych o defaultowej pojemności a następnie bufora zawierającego
obiekty prostej klasy napisanej przez siebie.