Solved

How do I get this to work?

Posted on 2007-11-23
3
195 Views
Last Modified: 2013-11-23
I can't seem to get this to work. I keep getting the same error message... invalid method declaration; return type required...

Can anyone help?  

Also, will this code really work?
public class PQFinal extends MinHeap
{
  private Comparable[] theHeap;
  private int elems;
  private int cap = 10;
  private int priority;
  private int size;
  
  public static String MyPriorityQueue(int n)
  {
    Comparable[] arr = new Comparable[size];
    elems = 0;
    priority = 1;
  }
  
  public static String MyPriorityQueue()
  {
    Comparable[] arr = new Comparable[cap];
    priority = 1;
    elems = 0;
  }
  
  public boolean isFull()
  {
    if(elems == cap)
      return true;
    else
      return false;
  }
  
  public boolean isEmpty()
  {
    if(elems == 0)
      return true;
    else
      return false;
  }
  
  public boolean enqueue(Comparable o)
  {
  
  }
  
  public Object dequeue()
  {
    Object o = new Object();
    return o;
  }
  
  public static String MyMinHeap()
  {
    cap = 10;
    size = 0;
    theHeap = new Comparable[10];
  }
  
  public MyMinHeap(Comparable[] arr, int n)
  {
    size = n;
    cap = arr.length;
    theHeap = arr;
      return size;
  }
  
  public int getSize()
  {
    if(size != 0)
      return theHeap;
    return -1;
  }
  
  public boolean add(Comparable o)
  {
    if (o == null)
      throw new IlegalArgumentException();
      
    if(size >= theHeap.length - 1)
      theHeap = resize(elem);
      
    size++;
    theHeap[size] = o;
  }
  
  public Object removeMin()
  {
    if(size <= 0)
      return -1;
    swap(1, size--);
    shiftDown(1);
    return theHeap[size];
  }
  
  private void shiftDown(int index)
  {
    int lc = leftChild(i);
    int rc = rightChild(i);
    if(lc < size)
    {
      if((rc < size) && (theHeap[rc] > theHeap[lc]))
        lc = rc;
      if(theHeap[i] < theHeap[lc])
      {
        swap(i, lc);
        shiftDown(lc);
      }
    }
  }
  
  private void buildHeap()
  {
    for(int i = size; i >= 0; i++)
      shiftDown(i);
  }
  
  public void parseInts()
  {
    return data.parseInts();
  }
  
  public void parseStrings()
  {
    return data.parseStrings();
  }
}

Open in new window

0
Comment
Question by:javalurnin
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 20340314
 public MyMinHeap(Comparable[] arr, int n)

needs to be

  public void MyMinHeap(Comparable[] arr, int n)
0
 
LVL 7

Expert Comment

by:UrosVidojevic
ID: 20340327
 public PQFinal(Comparable[] arr, int n)
  {
    size = n;
    cap = arr.length;
    theHeap = arr;
      return size;
  }

If you wanted this method to be constructor...
0
 
LVL 92

Accepted Solution

by:
objects earned 250 total points
ID: 20340782
>  public boolean enqueue(Comparable o)
>  {

>  }

looks like that should be:

  public boolean enqueue(Comparable o)
  {
         return add(o);  
  }
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question