Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "FifoElement.hpp"
- template <typename T>
- class Fifo {
- FifoElement<T>* head;
- FifoElement<T>* tail;
- public:
- /*Fifo& operator<<(const T&) {
- push(T);
- };
- Fifo& operator>>(const T&);
- operator int() const;*/
- Fifo() {
- head = nullptr;
- tail = nullptr;
- }
- void push(T input) {
- FifoElement<T>* element = new FifoElement<T>;
- element->value = input;
- element->next = nullptr;
- if (head == nullptr) {
- head = element;
- }
- if (tail) {
- tail->next = element;
- }
- tail = element;
- }
- T pop() {
- if (!head) {
- throw "Fifo Unterlauf";
- }
- if (tail == head) {
- T tmp = tail->value;
- tail = 0;
- return tmp;
- }
- FifoElement<T>* temp = head;
- head = head->next;
- T deleted = temp->value;
- return deleted;
- }
- void show() {
- FifoElement<T>* temp = head;
- do {
- cout << temp->value << endl;
- temp = temp->next;
- } while (temp);
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement