deleteElement(int[] heap, int index, int len) { mutex.lock();
heap[index] = heap[len-1];
len--;
while(2*index + 1 < len && (heap[index] > heap[2*index+1]|| heap[index] > heap[2*index +2])) {
int swapi = heap[2*index+1] < heap[2*index +2]) ? 2*index+1 : 2*index+2;
swap(heap,index,swapi);
index = swapi;
}
mutex.unlock();
} import java.util.Stack;
//单例模式的 栈
public synchronized class SyncStack{
volatile private Stack<Object> stack = new Stack<>();
private SyncStack(){
}
public Stack<Object> getStack(){
return this.stack;
}
public Object getElement(int index){
if(index<0 ||index > (this.stack.size()-1){
return null;
}
this.stack.get(index);
}
public void removeELement(int index){
if(index<0 || index > (this.stack.size()-1)){
return;
}
this.stack.remove(index);
}
}