Beispiel #1
0
    /*
     * enqueue method will place a new node inside the Queue at the front
     * Parameters:	(AIPolygon)polygonToAdd is the polygon that needs to be added
     *                                                                                      to a node to add into the queue
     * Return:	None
     */
    public void enqueue(AIPolygon polygonToAdd)
    {
        AIPolygonNode newNode = new AIPolygonNode(polygonToAdd, front);

        front = newNode;
        size++;
    }
Beispiel #2
0
    /*
     * dequeue method will remove the top Node from the Queue and return the AIPolygon being
     *      held inside the node being removed
     * Parameters:	None
     * Return:	(AIPolygon)
     *							null if the queue is empty
     *							the AIPolygon being held if the queue is not empty
     */
    public AIPolygon dequeue()
    {
        AIPolygonNode temp = front;

        front = temp.getNextNode();
        size--;
        return(temp.getPolygon());
    }
Beispiel #3
0
    /*
     *	getPolygonAtIndex will find a AIPolygonNode at a certian point inside the Queue
     *		and return the AIPolygon being held inside the node. It will not remove the
     *		Node from the Queue
     *	Parameters:	(int)index is the index in the Queue that the caller wants sent back
     *	Return:			(AIPolygon)
     *									the AIPolygon at the index in the Queue
     */
    public AIPolygon getPolygonAtIndex(int index)
    {
        if (index == 0)
        {
            return(front.getPolygon());
        }
        AIPolygonNode temp = front;

        for (int count = 0; count < index; count++)
        {
            temp = temp.getNextNode();
        }
        return(temp.getPolygon());
    }
Beispiel #4
0
    /*
     *	deleteNodeOfID method will delete the node at a certian index in the Queue. It will Not
     *			return the AIPolygon being held or the AIPolygonNode
     *	Parameters:	(int)idToDelete is the position at which the caller want the node to delete
     *	Return:	None
     */
    public void deleteNodeOfID(int idToDelete)
    {
        AIPolygonNode tempFront = front;

        if (front != null)
        {
            if (front.doesIDMatch(idToDelete) == true)
            {
                front = front.getNextNode();
                return;
            }
            AIPolygonNode tempBack = front.getNextNode();
            while (tempBack.getNextNode() != null && tempBack.doesIDMatch(idToDelete) == false)
            {
                tempFront = tempBack;
                tempBack  = tempFront.getNextNode();
            }
            if (tempBack.doesIDMatch(idToDelete) == true)
            {
                tempFront.setNextNode(tempBack.getNextNode());
                return;
            }
        }
    }
 /*
  *	setNextNode method will take in a new NextNode reference from the caller and
  *			set the nextNode reference to the new Node reference
  *	Parameter:	(AIPolygonNode) newNextNode is the new reference for NextNode
  *	Return:	None
  */
 public void setNextNode(AIPolygonNode newNextNode)
 {
     nextNode = newNextNode;
 }
    AIPolygon polygon;      // the polygon being held


    /*
     *	AIPolygonNode is the constructor for this class. It will set the AIPolygon being held
     *		, and the initial reference to the next Node in the queue
     *	Parameter:	(AIPolygon)thisPolygon is the AIPolygon needing to be held by this Node
     *							(AIPolygonNode)nextPolygonNode is the initial reference to the next Node
     *									in the queue
     *	Return:	None
     */
    public AIPolygonNode(AIPolygon thisPolygon, AIPolygonNode nextPolygonNode)
    {
        polygon  = thisPolygon;
        nextNode = nextPolygonNode;
    }
Beispiel #7
0
    int size;            //this is the size of the queue


    /*
     * AIPolygonQueue is the constructor for this class. It will set up the queue as
     *      empty
     */
    public AIPolygonQueue()
    {
        front = null;
        size  = 0;
    }