0

The question is this

Your task is to implement a heap that can work with any backing storage. Basically you need to take the abstraction one step down – for instance we use the heap without worrying about the backing storage simply because the interface is well defined. So you need to design an interface for the backing storage so that methods implementing the heap interface will work for any backing storage. Your code should be developed in Java and it should work for any data type that extends the comparable class. In this part you only need to worry about two backing storages; array and linked structure. You need to provide the implementation for the two backing storages as well.

I'm struggling to understand what exactly should be done here. What i get is, the interface should work regardless of the backing storage type (arrays/linked lists) How can i implement the interface without a specific backing storage? The interface should supposedly include the add and remove function. Hope someone could shed some light on this problem. Thank you

EDIT this is my heap interface,

public interface HeapInterface<T extends Comparable<T>>{
 public boolean isEmpty();
 public void add(T value);
 public T remove();
 public void show();
}

and this is the declaration for the array implementation

public class arrayHeap<T extends Comparable<T>> implements HeapInterface {

wondering if there is anything wrong with the declarations because once I implement the add(T value) method inside the array implementation i get a bunch of errors

7
  • You interpreted the question wrong ! , Take a deep breath please read it again Commented Mar 14, 2015 at 11:00
  • i've read this quite a few times, i don't see it differently could you please explain? Commented Mar 14, 2015 at 11:03
  • 2
    You need to write an Heap interface which defines all method a client can call on an instance of your heap. Then write two classes which implements this new interface and uses an array (class 1) or a LinkedList (class 2) version. Commented Mar 14, 2015 at 11:07
  • oh i see! thanks that was helpful :) one small problem, what is a "data type that extends the comparable class" ? Commented Mar 14, 2015 at 12:16
  • 1
    This bunch of problems comes with a bunch of error messages indicating what and where the problems are. You need to read them. Also, classes always start with an uppercase letter, by convention. I think you should tell your teacher that implementing generic collections is an advanced task, that shouldn't be done if you haven't learned to spell classes correctly or read error messages. Commented Mar 14, 2015 at 13:34

1 Answer 1

1

The issue was understanding the question properly which was beautifully explained by @Tom as follows

"You need to write an Heap interface which defines all method a client can call on an instance of your heap. Then write two classes which implements this new interface and uses an array (class 1) or a LinkedList (class 2) version"

Once i followed this, i ran into a few problems, which I added on to my initial post under EDIT. This turned out to be declaration issues for the implementation of the heap interface and the array implementation.

The fixed declarations

public interface HeapInterface<T>

public class ArrayHeap<T extends Comparable<T>> implements HeapInterface<T>

Thank you for all the help!

Sign up to request clarification or add additional context in comments.

1 Comment

public interface HeapInterface<T> could still be public interface HeapInterface<T extends Comparable<T>>, important is, that you use ...implements HeapInterface<T> instead of your old implements HeapInterface. The latter is called raw type is the same as implements HeapInterface<Object>.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.