Queue class help

So I'm trying to implement a Queue using a Linked List, but when I put my Queue to the test with the Radix sort (I got that code elsewhere), the output is:


--------------------------------------------------

Test RadixSort()
Original Array: 5 8 0 2 4 1 7 9 3 6


Process returned -1 (0xFFFFFFFF) execution time : 0.334 s

I don't know what is the cause of the program returning a -1
Any help is welcomed


LinkedList.h
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
38
39
40
41
42
43
44
45
46
47
48
49
#ifndef LINKEDLIST_H
#define LINKEDLIST_H

using namespace std;

template <class T>
    struct Node {
            T value;
            Node<T> *next;
            Node<T> *prev;
            Node() : value(T()), next(NULL), prev(NULL) {}
            Node(T v) : value(v), next(NULL), prev(NULL) {}
            T getValue() { return value; }
            void setValue(T v) { value = v; }
    };

template <class T>
    class LinkedList {
        private:
            Node<T> *header;
        public:
            LinkedList() {
                header = new Node<T>();
                header->next = header;
                header->prev = header;
            }
            ~LinkedList() {
                while (header->next != header)
                    delete header;
            }

            void insert(T n) {
                Node<T> *newNode = new Node<T>(n);
                newNode->prev = header->prev;
                newNode->next = header;
                newNode->prev->next = newNode;
                newNode->next->prev = newNode;
            }

            void erase() {
                header->next->prev->next = header->next->next;
                header->next->next->prev = header->next->prev;
                delete header;
            }

            Node<T>* begin() { return header->next; }
            Node<T> *end() { return header; }
};
#endif // LINKEDLIST_H 


Queue.h
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#ifndef QUEUE_H
#define QUEUE_H
#include "LinkedList.h"

using namespace std;

template <class T>
class Queue{
    private:
        LinkedList<T> data;
        int numdata = 0;
    public:
        Queue();
        ~Queue();
        bool empty();
        int size();
        T& front();
        T& back();
        void push_back(const T);
        void pop_front();
};

template <class T>
Queue<T>::Queue(){
    numdata = 0;
}

template <class T>
Queue<T>::~Queue(){
}

template <class T>
bool Queue<T>::empty(){
    if(numdata <= 0)
        return true;
    else false;
}

template <class T>
int Queue<T>::size(){
    return numdata;
}

template <class T>
void Queue<T>::push_back(const T value){
    numdata++;
    data.insert(value);
}

template <class T>
void Queue<T>::pop_front(){
    numdata--;
    data.erase();
}

template <class T>
T& Queue<T>::front(){
    return data.begin()->value;
}

template <class T>
T& Queue<T>::back(){
    T val = data.end()->prev;
    return val;
}

#endif 


main.cpp
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <string>
#include <iostream>
#include "Queue.h"
using namespace std;

void drawLine()
{
	cout << endl << string(50, '-') << endl << endl;
}

void radixSort(int *a, int n)
{
	const int radix = 10;
	int digits = 10;
	Queue<int> queues[radix];
	for(int i = 0, factor = 1; i < digits; factor *= radix, i++)
	{
		for(int j = 0; j < n; j++)
			queues[((a[j]/factor)%radix)].push_back(a[j]);
		int k = 0;
		for(int j = 0; j < radix; j++)
		{
			while(!queues[j].empty())
			{
				a[k] = queues[j].front();
				queues[j].pop_front();
				k++;
			}
		}
	}
}

void testRadixSort()
{
	drawLine();
	cout << "Test RadixSort()" << endl;
	int a[] = {5, 8, 0, 2, 4, 1, 7, 9, 3, 6};
	cout << "Original Array: ";
	for(int i = 0; i < 10; i++)
		cout << a[i] << " ";
	cout << endl << endl;
	radixSort(a, 10);
	cout << "RadixSort: ";
	for(int i = 0; i < 10; i++)
		cout << a[i] << " ";
	cout << endl;
}

int main()
{
	testRadixSort();
	return 0;
}
closed account (48T7M4Gy)
FWIW cpp shell gives:


--------------------------------------------------

Test RadixSort()
Original Array: 5 8 0 2 4 1 7 9 3 6 

 
Exit code: 0 (normal program termination)
Topic archived. No new replies allowed.