私は2つのLinkedListを持っています:newLinkedListとoldLinkedListはどちらもBIDクラスオブジェクトを含んでいます。以下は私のBIDクラスです:Javaのクラス変数に基づくユーザー定義オブジェクトの2つのLinkedListのカスタムソート
public class Bid {
private int quantity;
private double bidPrice;
public int getQuantity() {
return quantity;
}
public void setQuantity(int quantity) {
this.quantity = quantity;
}
public double getBidprice() {
return bidPrice;
}
public void setBidprice(double bidPrice) {
this.bidPrice = bidPrice;
}
}
今私はBIDクラスの価格変動に基づいてnewLinkedListとoldLinkedListのソートされた要素を含む新しいLinkedListlistを作成する必要があります。 もし私が両方のLinkedListで同じ価格を取得したら、私はnewLinkedList BIDクラスオブジェクトを保持し、古いものを削除しなければなりません。
つまり、新しいLinkedListにはprice変数に基づいてソートされたBidクラスオブジェクトが含まれている必要があります。
これは私の主な機能です:
public static void main(String[] args) throws InterruptedException, IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter size of linkedlist 1 ");
int size1 = Integer.parseInt(br.readLine());
System.out.println("Enter size of linkedlist 2 ");
int size2 = Integer.parseInt(br.readLine());
LinkedList<Bid> oldLinkedList= addElementsToList(size1);
LinkedList<Bid> newLinkedList= addElementsToList(size2);
/*
SORT BOTH THE LINKED LISTS HERE
*/
}
public static LinkedList<Bid> addElementsToList(int size) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
LinkedList<Bid> bidList = new LinkedList<Bid>();
for (int i = 0; i < size; i++) {
Bid bid = new Bid();
System.out.println("Enter bid price of Object " + i);
bid.setBidprice(Double.parseDouble(br.readLine()));
System.out.println("Enter bid quantity of Object " + i);
bid.setQuantity(Integer.parseInt(br.readLine()));
bidList.add(bid);
}
return bidList;
}
あなたは2つのリンクされたリストを持っています..そして、入れ子になったforループ、コンパレータなどを使用してください – emotionlessbananas
あなたの質問は何ですか? – Turing85
"2つのリンクされたリストを1つに統合し、最終的なリストをソートします。"しかし、LinkedListには "Bid"クラスオブジェクトが含まれています。したがって、並べ替えは「入札」クラスオブジェクトの価格変数に基づいて行われなければなりません。 –