Use the Linked stack class to support an application that tracks the status of a
ID: 3549627 • Letter: U
Question
Use the Linked stack class to support an application that tracks the status of an online auction. Budding begins at 1(dollars, pounds, euros, or whatever) and proceeds in increments of at least 1. If a bid arrives that is less than the current bid, it is discarded. If a bid arrives that is more than the current bid, but less than the maximum bid by the current high bidder, then the current bid for the current high bidder is increased to match it and the new bid is discarded. If a bid arrives that is more than the maximum bid for the current high bidder, then the new bidder becomes the current high bidder, at a bid of one more than the previous high bidder
Explanation / Answer
// Algorithm
// Assumption - Bidder object - { bid value, bidder name }
LinkedStack onlineAuctionTracker; // Top of the stack represents the current high bidder
LLObjectNode maxBidder; // Maximum bid of the current high bidder
onlineAuctionTracker.push(defaultBid); // Create a linked stack with one object (first bid with a value '1' and no name)
maxBidder = defaultBid;
while(end of input){
ifnewBidVal <= onlineAuctionTracker.top().getBidVal()) {
continue; //This bid is discarded
}
else if((onlineAuctionTracker.top().getBidVal() < newBidVal) && newBidVal <= maxBidder.getInfo().getBidVal())){
// create newHighBid object - bid value - newBidVal, bidder - (onlineAuctionTracker.top().getBidder())
onlineAuctionTracker.push(newHighBid);
}
else if(newBidVal > maxBidder.getInfo().getBidVal()){
// Update the current high bidder object - top of the linkedStack
if(1 == onlineAuctionTracker.sizels()){
newHighBidder.bidVal = onlineAuctionTracker.top.getBidVal();
}
else{
newHighBidder.bidVal = maxBidder.getInfo().getBidVal() + 1;
}
newHighBidder.bidder = newBidder;
onlineAuctionTracker.top.setInfo(newHighBidder);
newHighBidder.bidVal = newBidVal;
maxBidder.setInfo(newHighBidder);
}
}
toString method has to be defined for bidder class to get the bidder and bid value format.
To get the desired output, toString method implemented for LinkedStack can be used with proper formatting to print all the elements in the onlineAuctionTracker
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.