#ifndef MYQUEUE_Q
#define MYQUEUE_Y
#include "node.h"
#include <cstdlib>
template <class objT>
class myqueue {
private:
node<objT> * it; node<objT> * head;
public:
objT read() {if (it != NULL) return it -> data;}
bool lineup(objT o, bool test)
{
//cout << "thesize = " << thesize();
staticbool second = false;
int q = thesize(); cout << "Q = " << q << endl;
if (test) if (second || !second) {cout << "second = " << second << endl; } //exit(10000); }
if (q == 0)
//if (!thesize())
{cout << "inside this loop\n";
second = false;
if (it == NULL)
{
it = new node<objT>;
it -> data = 0;
it -> next = NULL;
//second = true;
}
}
//we make it here
if (!second)
{
it -> data = o;
second = true;
returntrue;
}
//we make it here
cout << "we make it here\n";
//if (it -> next != NULL) {if (test) exit(42); }
if (it -> next == NULL) ;
//bool tb = it -> next == NULL;
//cout << "tb = " << tb << endl;
cout << "We don't make it here\n";
//while (!(it -> next == NULL) )
while (it -> next != NULL)
{
cout << "we do not even make it here also.\n" << endl;
it = it -> next;
}
//we do not make it here
it -> next = new node<objT>;
it = it -> next;
it -> data = o;
it -> next = NULL;
it = head;
returntrue;
}
objT dequeue()
{
if (it != NULL)
{
objT dat = read(); //it -> data;
node<objT> * T = it -> next;
it = T; head = it;
return dat;
}
}
int thesize()
{
if (it != NULL)
{//cout << "inside if\n";
int counter = 1;
node<objT> * T; T = it;
//cout << "after declaration\n";
while (T -> next != NULL)
{ T = T -> next; ++counter; }
//cout << "after while\n";
it = head;
//cout << "counter = " << counter << endl;
cout << "counter = " << counter << endl;
return counter;
}//
return 0;
}
void discard(){
if (it != NULL)
{
node<objT> * T = it -> next;
it = T;
head = it;
return;
}
}
myqueue()
{
it = new node<objT>;
head = new node<objT>;
head = it;
it -> next = NULL;
}
myqueue(const myqueue & rhs)
{
it = rhs;
head = it;
}
myqueue(const objT & o)
{
it = new node<objT>;
head = new node<objT>;
it -> data = o;
it -> next = NULL;
head = it;
}
};
#endif
usingnamespace std;
#include <iostream>
#include "myqueue.h"
#include <stdio.h>
usingnamespace std;
int main()
{
myqueue<int> list;
//int a = 5, b = 10, c = 0, d = -3, e = 12;
list.lineup(5, 0); list.lineup(10, 0); list.lineup(0, 0); list.lineup(-3, 0); list.lineup(12, 0); list.lineup(5, 0); list.lineup(200, 0);
cout << "The size of the list = " << list.thesize() << endl;
cout << "The size of the list = " << list.thesize() << endl;
cout << "First the top of the list = " << list.read() << endl;
list.discard();
cout << "I am removing a " << list.dequeue() << " from the list.\n" << endl;
cout << "I am removing a " << list.dequeue() << " from the list.\n" << endl;
cout << "The top of the list = " << list.read() << endl;
//cout << "Now the size = " << list.thesize() << endl;
cout << "before discarding the size = " << list.thesize() << endl;
int size = list.thesize();
for (int i = 0; i < size; ++i)
list.discard();
cout << "after discarding the size = " << list.thesize() << endl;
list.lineup(1000, 0); cout << "after list.lineup()\n"; list.lineup(2000, 1); exit(96); //list.lineup(3000); list.lineup(4000);
cout << "the top = " << list.read() << endl;
cout << "thesize = " << list.thesize() << endl;
printf("\nYou have reached the end of test.cpp\n");
//cout << "You have reached the end of test.cpp\n" << endl;
return 1050;
}