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

Priyath Gregory
  • 927
  • 1
  • 11
  • 37
  • You interpreted the question wrong ! , Take a deep breath please read it again – Neeraj Jain Mar 14 '15 at 11:00
  • i've read this quite a few times, i don't see it differently could you please explain? – Priyath Gregory Mar 14 '15 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. – Tom Mar 14 '15 at 11:07
  • oh i see! thanks that was helpful :) one small problem, what is a "data type that extends the comparable class" ? – Priyath Gregory Mar 14 '15 at 12:16
  • Something like `public class Person implements Comparable`. Mind that `Comparable` is an interface, not a class. – Tom Mar 14 '15 at 12:44
  • @Tom I implemented the interface and ran into a bunch of problems, i have edited the question to explain the current situation. Wasn't sure if i was supposed to start a new thread, apologies if that's the case – Priyath Gregory Mar 14 '15 at 13:17
  • 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. – JB Nizet Mar 14 '15 at 13:34

1 Answers1

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!

Priyath Gregory
  • 927
  • 1
  • 11
  • 37
  • 1
    `public interface HeapInterface` could still be `public interface HeapInterface>`, important is, that you use `...implements HeapInterface` instead of your old `implements HeapInterface`. The latter is called *raw type* is the same as `implements HeapInterface`. – Tom Mar 14 '15 at 20:17