Here is my code:
public DoubleEndedPriorityQueue(){
max = new MaxPQ<Element>();
min = new MinPQ<Element>();
}
public void insert(Key item){
Element thisElement = new Element(item);
Element thatElement = new Element(item);
thisElement.element = thatElement;
thatElement.element = thisElement;
max.insert(thisElement);
min.insert(thatElement);
}
private class Element{
Key item;
Element element;
private Element(){}
private Element(Key item){
this(item,null);
}
private Element(Key item,Element element){
this.item = item;
this.element = element;
}
}
}
i create a data-structure to store a key and the reference pointing to the element which stored the same key in another array(the priority queue is implemented by the array),the problem is:if i find a element in an array ,i want to find the element with the same key in another array in o(1) which means i can know its index in O(1), how can i do it?