第四题写完辣
This commit is contained in:
+29
-3
@@ -1,4 +1,5 @@
|
||||
//test4.cpp
|
||||
#include <iomanip>
|
||||
#include<iostream>
|
||||
#include"LinkList.h" //LinkList类见实验一
|
||||
using namespace std;
|
||||
@@ -20,12 +21,37 @@ void create_with_count(bookList &l, int count) {
|
||||
}
|
||||
}
|
||||
|
||||
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() {
|
||||
bookList books = new bookNode;
|
||||
books->next = NULL;
|
||||
int count;
|
||||
bookList books = new bookNode;
|
||||
double max_price;
|
||||
books->next = NULL;
|
||||
cin >> count;
|
||||
create_with_count(books, count);
|
||||
display(&books);
|
||||
max_price = find_max_price(&books);
|
||||
cout << max_price << endl;
|
||||
display_max_prices(&books, max_price);
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user