help with illegal start of expression in a heap please
hello, i am new to java and i am trying to figure out how to make a heap, then remove the max element (from root), add a new element, and reheap. i don't know if i did it correctly, but the only error that i have now is illegal start of expression. please help if you can - thanks
package dataStructures;
publicclass MaxHeapExtendedextends MaxHeap{
// NO additional data members allowed
// constructors go here
publicvoid changeMax(Comparable c){
// your code goes here
//I NEED TO REMOVE THE MAXIMUM ELEMENT (remove)
{
// if heap is empty
if (size == 0){
returnnull;
}
//the maximum element is in position 1
Comparable maxElement = heap[1];
//initialize
Comparable lastElement = heap[size--];
//build last element from root
int currentNode = 1,
//child of currentNode
child = 2;
while (child <= size){
// heap[child] should be larger child of currentNode
if (child < size && heap[child].compareTo(heap[child + 1]) < 0){
child++;
}
//should i put lastElement in heap[currentNode]?if yes:
if (lastElement.compareTo(heap[child]) >= 0){
break;
}
else{
//moves the child up a level
heap[currentNode] = heap[child];
//moves the child down a level
currentNode = child;
child *= 2;
}
heap[currentNode] = lastElement;
}
//I NEED TO ADD THE NEW ELEMENT TO REPLACE ONE THAT WENT AWAY (put)
{
// increase array size if necessary
if (size == heap.length - 1){
heap = (Comparable []) ChangeArrayLength.changeLength1D
(heap, 2 * heap.length);
}
// find place for theElement
// currentNode starts at new leaf and moves up tree
int currentNode = ++size;
while (currentNode != 1 && heap[currentNode / 2].compareTo(theElement) < 0){
// cannot put theElement in heap[currentNode]
heap[currentNode] = heap[currentNode / 2];// move element down
currentNode /= 2;// move to parent
}
heap[currentNode] = theElement;
}
//I NEED TO REHEAP
{
heap = theHeap;
size = theSize;
// heapify
for (int root = size / 2; root >= 1; root--){
Comparable rootElement = heap[root];
// find place to put rootElement
int child = 2 * root;// parent of child is target
// location for rootElement
while (child <= size){
// heap[child] should be larger sibling
if (child < size && heap[child].compareTo(heap[child + 1]) < 0){
child++;
}
// can we put rootElement in heap[child/2]?
if (rootElement.compareTo(heap[child]) >= 0){
break;// yes
}
else{
// no
heap[child / 2] = heap[child];// move child up
child *= 2;// move down a level
}
heap[child / 2] = rootElement;
}
}
}
publicstaticvoid main(String [] args){
/* 8
/\
76
/ \/
35 1
*/
// test constructor and put
MaxHeapExtended h =new MaxHeapExtended(6);
h.put(new Integer(8));
h.put(new Integer(7));
h.put(new Integer(6));
h.put(new Integer(3));
h.put(new Integer(5));
h.put(new Integer(1));
System.out.println("Elements in array order were");
System.out.println(h);
h.changeMax(new Integer(4));
System.out.println("Elements in array order after change are");
System.out.println(h);
}
}
}
}

