views:

148

answers:

2
public class MaxHeap<T extends Comparable<T>> implements Heap<T>{
 private T[] heap;
 private int lastIndex;
 private static final int defaultInitialCapacity = 25;

 public void add(T newItem) throws HeapException{
  if (lastIndex < Max_Heap){
   heap[lastIndex] = newItem;
   int place = lastIndex;
   int parent = (place – 1)/2; //ERROR HERE**********
   while ( (parent >=0) && (heap[place].compareTo(heap[parent])>0)){
    T temp = heap[place];
    heap[place] = heap[parent];
    heap[parent] = temp;
    place = parent;
    parent = (place-1)/2;
  }else {
   throw new HeapException("HeapException: Heap full"); }
  }
 }

Eclipse complains that there is a:

"Syntax error on token "Invalid Character", invalid AssignmentOperator"

With the red line beneath the (place-1)

There shouldn't be an error at all since it's just straight-forward arithmetic. Or is it not that simple?

+5  A: 

You did not actually use a minus (-) sign, but something else.

Try to delete it and add another - sign instead.

Peter Lang
Thanks. Utter fail on my side cheers :)
Kay
+2  A: 

That's not a minus sign. It's an en dash (I think). Replace it with a proper minus sign and it should work.

Did you perhaps copy and paste this from somewhere else? Word processors like to mess with things like dashes and quotation marks.

Syntactic
Thanks Syntactic - you're right i did copy/paste some of it, thanks for the tip!
Kay