Summary Files Commits Branches @commit @diff @stats
path: root / Year 2 / Structures and data algorithms / HomeworkExamPrep / Queue / Queue_Static.hpp
blob: 2b9dc8dade94d38e196d224a826047a774cbbec3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#ifndef QUEUE_STATIC
#define QUEUE_STATIC

#include <stdexcept>
#define QUEUE_SIZE 1024

template <class T>
class Queue {
	T vals[QUEUE_SIZE];
	unsigned frontInd;
	unsigned backInd;

public:
	void push(const T& v);
	void pop();
	T& front();
};

template <class T>
void Queue<T>::push(const T& v) {
	vals[backInd++ % QUEUE_SIZE] = v;

	if (backInd == frontInd)
		throw std::logic_error("Queue overfill!");
}

template <class T>
void Queue<T>::pop() {
	frontInd++;
}

template <class T>
T& Queue<T>::front() {
	return vals[frontInd];
}

#endif