项目重启
This commit is contained in:
@@ -1,6 +0,0 @@
|
||||
cmake_minimum_required(VERSION 3.29)
|
||||
project(homework2)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
|
||||
add_executable(test1 test1.cpp)
|
||||
@@ -1,46 +0,0 @@
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
|
||||
using namespace std;
|
||||
|
||||
typedef struct node {
|
||||
string id;
|
||||
string name;
|
||||
double price;
|
||||
struct node *next;
|
||||
} node, *book_list;
|
||||
|
||||
void init_list(book_list *books) {
|
||||
*books = new node();
|
||||
(*books)->next = NULL;
|
||||
}
|
||||
|
||||
void create_from_end(book_list *books) {
|
||||
node *r = *books;
|
||||
node *s = new node();
|
||||
do {
|
||||
cin >> s->id >> s->name >> s->price;
|
||||
if (s->id == "0" && s->name == "0" && s->price == 0) {
|
||||
r->next = NULL;
|
||||
} else {
|
||||
r->next = s;
|
||||
}
|
||||
r = r->next;
|
||||
} while (r != NULL);
|
||||
}
|
||||
|
||||
void display(book_list *books) {
|
||||
while ((*books)->next != NULL) {
|
||||
*books = (*books)->next;
|
||||
cout << (*books)->id << " " << (*books)->name << " " << fixed << setprecision(2) << (*books)->price << endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int main() {
|
||||
book_list *books;
|
||||
init_list(books);
|
||||
create_from_end(books);
|
||||
display(books);
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user