//
// testque.cpp
//
// Test of linked-list-based queue implementation in qlink.hpp
//
// Computer Science S-111, Harvard University
//

#include <iostream.h>
#include "../util/getinput.hpp"
#include "qlink.hpp" 


//
// queue_action - used by stack::traverse to print each item in
// a queue of standard strings
//
void
queue_action(int pos, char* item)
{
    cout << pos << " " << item << "\n";
}

int
main()
{
    queue<char *> que(10);
    char buf[80];
    char *str;

    cout << "\nCommands:";
    cout << "\ni <string>: Insert string at rear of queue";
    cout << "\nr: Remove string from front of queue";
    cout << "\nn: Reinitialize queue";
    cout << "\nl: List queue";
    cout << "\nq: Quit\n";

    while (true) {
	cout << ("\n[iNSERT string | rEMOVE | REInIT | lIST | qUIT] : ");
	cin.getline(buf,80);

	if (*buf == 'q')
	    exit(1);
	else if (*buf == 'i') {
	    str = strsave(buf + 1);
	    if (!que.insert(str))
		cout << "Queue is full\n";
	}
	else if (*buf == 'r') {
	    if (!que.remove(str))
		cout << "Queue is empty\n";
	    else 
		cout << " got <" << str << ">\n";
	}
	else if (*buf == 'n')  {
	    que.reinit();
	}
	else if (*buf == 'l') {
	    if (que.empty())
		cout << "Queue is empty\n";
	    else
		que.traverse(&queue_action);
	}
    }
}
