/*------------------------------------------------------------------------------
Description:  Olist class
Author: Chris Huyler
Language: Builder C++
Name: Olist.h
Date: April 18, 2000
------------------------------------------------------------------------------*/

#include "list.h"

template <class E>
class Olist : public list<E> {
	public:
        bool rotate(E& target); // rotates officer to back of list
        void insert(E& item);   // redefined insert, adds officers to end of list

};


template <class E>
bool Olist<E>::rotate(E& target)
{
	node<E> *prev = NULL;
    bool found = false;
    node<E> *cursor = front;
    while((!found) && (cursor!=NULL))
    {
    	if((cursor->itm) == target)
      {
        	found = true;
            if (cursor == front)
            	front = front -> next;
            else
            	prev -> next = cursor -> next;
            insert(cursor->itm);             // reinsert item at bottom of list
            delete cursor;
        }
        else
        {
        	prev = cursor;
            cursor = cursor -> next;
        }
    }
    return(found);
}


template <class E>
void Olist<E>::insert(E& item)
{
	node<E> *ptr;
   ptr = new node<E>(item);
   if(front == NULL)
   {
   	size = 0;
   	front = ptr;
   }
   else
   	back -> next = ptr;
   size++;
   back = ptr;
}

