私はPythonからJavaへの移行を行っていますが、Java構文に慣れ親しんでいます。私は優先度キュー(Python heapq
の類義語)で勉強していますが、いくつかの実装についてはわかりませんが、使用するためにコンパレータを作成する必要があるようです。Javaの別のリストからの値による優先キューのポップ要素
は、私は一連の値(int型)は、各バッファ要素に添付している、私は
buffer.poll() // return buffer element 2
buffer.poll() // return buffer element 0
buffer.poll() // return buffer element 1
欲しいキュー
Queue<Object> buffer;
// for example, pop buffer element according to `element.value`
// this is not the accurate code but helps illustrate my points
BufferElement0.value() // return 5
BufferElement1.value() // return 3
BufferElement2.value() // return 7
があるとします。これらの与えられた値に従ってバッファ要素をどのようにポップできますか?
更新
オブジェクトは、必要な数は
public class Message {
public final double timeStamp;
public final String text;
public final Topic topic;
public final Status status;
public final int value;
public Message(double timeStamp, String text, Topic topic, Status status, int value) {
this.timeStamp = timeStamp;
this.text = text;
this.topic = topic;
this.status = status;
this.value = value;
}
Queue<Message> msgs;
message = msgs.poll()
は、我々はそのmessage
のvalue
に応じmesssage
を開くことができ、オブジェクトがあると仮定しないのですか?
あなたの意図をより明確に示すために、入力例と期待される結果を提供してください。 –
あなたがここでやろうとしていることは、私にはまだ不明です。 – syntagma
私が今日見た中で最も混乱している説明 – Antoniossss