/* * PriorityQueueL.java * SORTED INSERT LIST IMPLEMENTATION * Created on March 3, 2008, 3:09 PM * * To change this template, choose Tools | Template Manager * and open the template in the editor. */ package priorityqueuetest; /** * * @author suchenek */ public class PriorityQueueL { private int count; private List itemList; private static List sortedInsert(int newItem, List P) { cnt.incr(); if ((P==null)||((newItem >= P.head) & Bcnt.incr())) { List N = new List(); N.head=newItem; N.tail=P; return(N); } P.tail=sortedInsert(newItem, P.tail); return(P); } public void insert(int newItem) { itemList=sortedInsert(newItem, itemList); count++; } public int remove() { if (count == 0) return -99999; //if the priority queue is empty, return minus infty int K = itemList.head; itemList=itemList.tail; count--; cnt.incr(); return(K); } public int size() { return count; } public boolean isEmpty() { return count==0; } public int Length() { return count; } }