Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- size_t TAB_SIZE_MAX = 10;
- size_t TAB_SIZE_MIN = 1;
- class BaseArraySizeException {
- protected:
- std::size_t size_;
- public:
- BaseArraySizeException(std::size_t size) : size_(size) {}
- ~BaseArraySizeException() {}
- virtual void printError() const = 0;
- };
- class TooSmallArrayException : public BaseArraySizeException {
- public:
- TooSmallArrayException(std::size_t size) : BaseArraySizeException(size) {}
- void printError() const {
- std::cerr << "Rozmiar tablicy: " << size_ << " jest mniejszy niz "
- << TAB_SIZE_MIN << "!" << std::endl;
- }
- };
- class TooBigArrayException : public BaseArraySizeException {
- public:
- TooBigArrayException(std::size_t size) : BaseArraySizeException(size) {}
- void printError() const {
- std::cerr << "Rozmiar tablicy: " << size_ << " jest wiekszy niz " << TAB_SIZE_MAX << "!" << std::endl;
- }
- };
- template <typename T>
- class Queue {
- private:
- int front, rear, max;
- T *q;
- public:
- Queue(int size = 0) {
- front = rear = 0;
- max = size;
- try {
- q = new T[size];
- } catch (const std::bad_alloc &e) {
- std::cerr << "Nie udalo sie zaalokowac pamieci: " << e.what() << std::endl;
- }
- }
- int push(T);
- T pop();
- ~Queue() {
- delete[]q;
- }
- };
- template <typename T>
- int Queue<T>::push(T elem) {
- if (front >= max)
- throw TooBigArrayException;
- q[front] = elem; front++;
- }
- template <typename T>
- T Queue<T>::pop() {
- if (front <= 0) {
- return -1;
- }
- T result = q[rear];
- ++rear;
- return result;
- }
- int main() {
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement