Hey again,
I'm having another problem unfortunately. We were asked to create a tree that has binary tree properties as well as max heap property.
(take A(7),C(8) and B(3) ; the tree should be so that the it should alphabetically represent a binary tree and numerically represent a heap)

I tried to create a treap but didn't succeed. so I thought that I'd create a priority queue and sort the items numerically and then remove them one by one and add to the tree, which will sort them in alphabetical order (The best I could come up with).

Now the problem is with the priority queue, it gives me an "operator < cannot be applied to int, java.lang,string " error msg.

``````public class PriorityQueue {

public String createString(int item, String str) {
String space, priort;
priort = Integer.toString(item);
space = " ";
totl = str + space + priort;
}

public int insertFirst(int item, String keys) {
String str = createString(item, keys);
insert(str, item);
}

public void insert(String str, int item) {
int i;

if (nItems == 0) {
queArray[nItems++] = str; // insert at 0
} else {
for (i = nItems - 1; i >= 0; i--)
{
if (item < queArray[i]) { // the error appears here
queArray[i + 1] = queArray[i];
} else {

break;
}
}
queArray[i + 1] = str;
nItems++;
}  (nItems > 0)
}

public void EmptyQueque() {
while (!isEmpty()) {
remove();
}
}

public void remove() {
if ((!isEmpty())) {
while (!isEmpty()) {
String str = queArray[--nItems];
System.out.println(str + " ");
}
}

public static void main(String[] args) {
PriorityQueue thePQ = new PriorityQueue(100);
thePQ.insertFirst(3, "H");
thePQ.insertFirst(10, "M");
thePQ.insertFirst(2, "O");
thePQ.insertFirst(5, "Hfsh");
thePQ.remove();

}
}``````

I wanted to have the createString method because it would be easier for me to just remove items and send it to the tree (is there another method?).
I understand that you can't compare int with the string inside the array but I'm really stuck here and haven't got any ideas.
Is there a way to add a string and integer in to a two-dimensional array or something?
Sorry about the long boring explanation, and thanx for taking the time to read it.
Any help will be much appreciated.

The reason for that error is not hard to determine: the operator < can only be applied to numeric types. String is a class, a String is an object, they can't be compared in this way. You want the compareTo() method. Read up on Comparable if you're not familiar with it, then use that to do your comparison.