Kay
Kay

Reputation: 845

Bizzare Java invalid Assignment Operator Error

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?

Upvotes: 2

Views: 5290

Answers (3)

Genaut
Genaut

Reputation: 1851

You can try Clean your project. Project -> Clean...

Works for me many times

Upvotes: 1

Syntactic
Syntactic

Reputation: 10961

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.

Upvotes: 2

Peter Lang
Peter Lang

Reputation: 55514

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

Try to delete it and add another - sign instead.

Upvotes: 6

Related Questions