DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 2005

    heap sorting problem

    I have tried a few different things to try to get this error to go away. I know it is a problem with the type of data that I am trying to pass but don't see why. Any help is appreciated.

    File: H:\Data Structures\HW7\heapSortImplementation.java [line: 24]
    Error: pqInsert(SearchKeys.KeyedItem) in PriorityQueues.PriorityQueue cannot be applied to (double)
     public double makeHeap()
        PriorityQueue prq = new PriorityQueue();
        FileReader freader = new FileReader("hw7input.txt");
        BufferedReader inputFile = new BufferedReader(freader);
        input = inputFile.readLine();
        double dinput = Double.parseDouble(input);
        while(input != null)
          prq.pqInsert(dinput);//this is the line the error is on
          input = inputFile.readLine();
          dinput = Double.parseDouble(input);
    here is the code for the searchkey
    package SearchKeys;
    public abstract class KeyedItem
      private Comparable searchKey;
      public KeyedItem(Comparable key)
        searchKey = key;
      }//end constructor
      public Comparable getKey()
        return searchKey;
      }//end getKey
    }//end KeyedItem
    This is from the PriorityQueue class
    public void pqInsert(KeyedItem newItem) throws PQueueException
        }//end try
        catch(HeapException e)
          throw new PQueueException("PQueueException: Priority queue full");
        }//end catch
      }//end pqInsert
    This is the method called in the the above method
    public void heapInsert(KeyedItem newItem) throws HeapException
        //inserts an item into a heap
        //Pre-condition: newItem is the item to be inserted
        //Post-condition: if the heap was not full, newITem is in its proper position; otherwise HeapException is thrown
        if(size < MAX_HEAP)
          //place the new item at the end of the heap
          items[size] = newItem;
          //trickle new item up to its proper position
          int place = size;
          int parent = (place - 1) / 2;
          while((parent >= 0) && (items[place].getKey().compareTo(items[parent].getKey())) < 0)
            //swap items[place and items[parent]
            KeyedItem temp = items[parent];
            items[parent] = items[place];
            items[place] = temp;
            place = parent;
            parent = (place - 1) / 2;
          }//end while
        }//end if
          throw new HeapException("HeapException: Heap full");
        }//end else
      }//end heapInsert

  2. #2
    Join Date
    Dec 2004
    San Bernardino County, California
    your KeyedItem class is abstract. Are you creating a class which inherits from this abstract class and implements the methods of this class at some point? If so, your "KeyedItem" object should be constructed in the child class ... Otherwise, I am surprised you aren't getting other errors ...

Similar Threads

  1. Problem while sorting the datagrid
    By dev11 in forum ASP.NET
    Replies: 1
    Last Post: 11-22-2005, 04:03 PM
  2. Heap Clearing
    By joshyravi in forum Java
    Replies: 1
    Last Post: 06-19-2005, 09:08 AM
  3. Replies: 0
    Last Post: 12-13-2001, 12:06 PM
  4. Arabic problem view
    By Ayman in forum VB Classic
    Replies: 0
    Last Post: 04-03-2000, 01:08 AM
  5. Problem with CryptoAPI and JCE
    By Jason Bock in forum VB Classic
    Replies: 0
    Last Post: 03-21-2000, 06:48 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.