Files
data-structures-and-algorithms/homework2/test4.cpp
T
2024-10-19 18:13:20 +08:00

58 lines
1.4 KiB
C++

//test4.cpp
#include <iomanip>
#include<iostream>
#include"LinkList.h" //LinkList类见实验一
using namespace std;
void create_with_count(bookList &l, int count) {
bookNode *input = new bookNode;
input->next = NULL;
bookNode *temp = l;
for (int i = 0; i < count; i++) {
cin >> input->id >> input->name >> input->price;
if (temp == l) {
l->next = input;
} else {
temp->next = input;
}
temp = input;
input = new bookNode;
input->next = NULL;
}
}
double find_max_price(bookList *l) {
bookNode *temp = (*l)->next;
double max = 0;
while (temp != NULL) {
if (temp->price > max) {
max = temp->price;
}
temp = temp->next;
}
return max;
}
void display_max_prices(bookList *l, double max_price) {
bookNode *temp = *l;
while (temp != NULL) {
if (temp->price == max_price) {
cout << temp->id << " " << temp->name << " " << fixed << setprecision(2) << temp->price << endl;
}
temp = temp->next;
}
}
int main() {
int count;
bookList books = new bookNode;
double max_price;
books->next = NULL;
cin >> count;
create_with_count(books, count);
max_price = find_max_price(&books);
cout << max_price << endl;
display_max_prices(&books, max_price);
return 0;
}