// File: gqmain1.C
//
// Testing generic queues implemented by the GenQ class.

#include <iostream.h>
#include <iomanip.h>
#include <stdlib.h>
#include "genq.h"

// Local function prototypes
//
int cmp_int(void *, void *) ;
void prnt_int(void *) ;


// Local function definitions
//
int cmp_int(void *vptr1, void *vptr2) {
   int *ptr1, *ptr2 ;

   ptr1 = (int *) vptr1 ;
   ptr2 = (int *) vptr2 ;

   if (ptr1 == NULL && ptr2 == NULL) return 0 ;  
   if (ptr1 == NULL) return -1 ;
   if (ptr2 == NULL) return  1 ;

   if (*ptr1 < *ptr2) return -1 ;
   if (*ptr1 == *ptr2) return 0 ;
   return 1 ;
}


void prnt_int(void *vptr) {
   int *ptr ;

   if (vptr == NULL) return ;

   ptr = (int *) vptr ;
   cout << *ptr << " " ;
}


main() {
   GenQ L(cmp_int, prnt_int) ;
   int *ptr, length ;

   L.enqueue(new int(5)) ;
   L.enqueue(new int(5)) ;
   L.enqueue(new int(2)) ;
   L.enqueue(new int(7)) ;
   L.enqueue(new int(5)) ;
   L.enqueue(new int(5)) ;
   L.enqueue(new int(13)) ;
   L.enqueue(new int(12)) ;
   L.enqueue(new int(11)) ;
   L.print() ;
   cout << endl ;
   length = L.length() ;
   cout << "length = " << length << endl ;
   cout << endl ;

   int x=5 ;
   L.remove(&x) ;
   L.print() ;
   cout << "\n" << endl ;

   L.enqueue(new int(17)) ;
   L.enqueue(new int(21)) ;
   L.print() ;
   cout << "\n" << endl ;

   ptr = (int *) L.dequeue() ;
   cout << "Removed item: " << *ptr << endl ;
   L.print() ;
   cout << "\n" << endl ;
   delete ptr ;

   ptr = (int *) L.peek() ; 
   cout << "First item: " << *ptr << endl ;
   L.print() ;
   cout << "\n" << endl ;

   delete L.dequeue() ;
   delete L.dequeue() ;
   delete L.dequeue() ;
   delete L.dequeue() ;
   delete L.dequeue() ;
   L.print() ;
   cout << endl ;
   delete L.dequeue() ;
   L.print() ;
   cout << endl ;
   L.enqueue(new int(1)) ;
   L.enqueue(new int(2)) ;
   L.enqueue(new int(3)) ;
   L.print() ;
   cout << "\n" << endl ;
}
