我有两个LinkedList:newLinkedList和oldLinkedList,都包含BID类对象。以下是我的投标类别:
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;
}
}
如果我在两个LinkedList中得到相同的价格,那么我必须保留新的LinkedList BID类对象,并删除旧的。
这意味着新的LinkedList必须包含根据价格变量排序的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;
}