Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <fstream>
- #include <exception>
- #define myQueue
- #define myAlg
- using namespace std;
- #ifdef myQueue
- template<class T>
- class Queue {
- struct Node {
- Node() {
- next = NULL;
- }
- Node(T el, Node * node)
- {
- data = el;
- next = node;
- }
- Node* next;
- T data;
- };
- Node* _top;
- Node* _front;
- int _size;
- public:
- Queue()
- {
- _front = new Node();
- _top = _front;
- _size = 0;
- }
- ~Queue()
- {
- while (_front != NULL && _front->next != NULL)
- {
- Node* temp = _front;
- _front = _front->next;
- delete[] temp;
- }
- }
- void push(T el);
- void pop();
- T front();
- int size();
- T peek();
- bool empty();
- };
- #endif // myQueue;
- #ifdef myAlg
- template<class T>
- int Queue<T>::size()
- {
- return _size;
- }
- template<class T>
- bool Queue<T>::empty()
- {
- return (!_size);
- }
- template<class T>
- void Queue<T>::push(T el) {
- _top->next = new Node(el, NULL);
- _top = _top->next;
- if (_size == 0)
- {
- _front = _top;
- }
- _size++;
- }
- template<class T>
- T Queue<T>::front() {
- return _front->data;
- }
- template<class T>
- T Queue<T>::peek()
- {
- if (_front == NULL || _front->next == NULL)
- return NULL;
- return _front->next->data;
- }
- template<class T>
- void Queue<T>::pop() {
- if (!_size)return;
- _front = _front->next;
- _size--;
- }
- #e
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement