开发者

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; //E开发者_开发问答RROR 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?


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

Try to delete it and add another - sign instead.


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.


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

Works for me many times

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜