help with queue
I am terrible at this and can't seem to make it work any help is appreciated.
main.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
#include <iostream>
#include<string>
#include <cstdlib>
#include "myqueue.h"
using namespace std;
int main()
{
myqueue meQueue(30);
for(long i = 3; i <40; i +=4)
{
meQueue.enque(i);
}
while(!meQueue.isEmpty())
{
cout << meQueue.deque() << "\n";
}
system("pause");
return 0;
}
|
myqueue.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
|
#ifndef MYQUEUE_H_
#define MYQUEUE_H_
class myqueue
{
private:
int head, tail, max_size,size;
long array[100];
public:
myqueue()
{
head = 0;
tail = -1;
size = 0;
max_size = 20;
}
myqueue(unsigned int input_size)
{
tail = -1;
head = 0;
size= 0;
if(input_size >=100)
{
max_size = 100;
}
else if (input_size <=2)
{
max_size = 10;
}
else
{
max_size= int(input_size);
}
}
bool enque(long item);
long deque();
bool isEmpty();
bool isFull();
};
#endif // MYQUEUE_H_
|
myqueue.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
|
#include <iostream>
#include <string>
#include "myqueue.h"
bool myqueue::enque(long time)
{
if(isFull())
{
return false;
}
tail = (tail +1) % max_size;
array[tail] = item;
size++;
return true;
}
long myqueue::deque()
{
if (isEmpty())
{
return (-100);
}
long hold = array[head];
head = (head+1)%max_size;
size--;
return hold;
}
bool myqueue::isEmpty()
{
return (size ==0);
}
bool myqueue::isFull()
{
return (size == (max_size-1));
}
|
Last edited on
#include "myqueue.cpp"
Don't include source (*.cpp) files, only include header (*.h;*.hpp) files.
Thanks that handled some errors. But now I'm having issues with myqueue.cpp file.
You forgot the return types on some of the functions (isEmpty and isFull).
It would be incredibly easy if you just read the error messages that your compiler is giving you.
Topic archived. No new replies allowed.