身首异处
This commit is contained in:
@@ -3,5 +3,6 @@ project(homework2)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
|
||||
add_executable(Test_LinkList LinkLits.cpp
|
||||
Test_LinkList.cpp)
|
||||
add_executable(test1 LinkLits.cpp
|
||||
test1.cpp
|
||||
LinkList.h)
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
#ifndef LINKLIST_H
|
||||
#define LINKLIST_H
|
||||
#include<string>
|
||||
using namespace std;
|
||||
|
||||
typedef struct bookNode {
|
||||
string id;
|
||||
string name;
|
||||
double price;
|
||||
bookNode *next;
|
||||
} book_node, *bookList;
|
||||
|
||||
bool isEmpty(bookList);
|
||||
|
||||
void insert(bookList &l);
|
||||
|
||||
void display(bookList *l);
|
||||
|
||||
#endif //LINKLIST_H
|
||||
@@ -1,23 +1,19 @@
|
||||
#include <iostream>
|
||||
#include<iomanip>
|
||||
#include"LinkList.h"
|
||||
using namespace std;
|
||||
|
||||
typedef struct bookNode {
|
||||
string id;
|
||||
string name;
|
||||
double price;
|
||||
bookNode *next;
|
||||
} book_node, *bookList;
|
||||
|
||||
bool is_list_empty(bookList *l) {
|
||||
bool isEmpty(bookList *l) {
|
||||
if ((*l)->next == NULL) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void display(bookList *l) {
|
||||
if (is_list_empty(l)) {
|
||||
if (isEmpty(l)) {
|
||||
printf("List is empty\n");
|
||||
} else {
|
||||
bookNode *temp = (*l)->next;
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
#include <iostream>
|
||||
#include "LinkLits.cpp"
|
||||
#include "LinkList.h"
|
||||
using namespace std;
|
||||
|
||||
void insert(bookList *l) {
|
||||
bookNode *temp = (*l)->next;
|
||||
void insert(bookList &l) {
|
||||
bookNode *temp = l;
|
||||
while (temp != NULL) {
|
||||
cin >> (*temp).id >> (*temp).name >> (*temp).price;
|
||||
if (!(((*temp).id == "" && (*temp).name == "" && (*temp).price == 0))) {
|
||||
temp = (*temp).next;
|
||||
if (!(((*temp).id == "0" && (*temp).name == "0" && (*temp).price == 0))) {
|
||||
temp = (*temp).next = new bookNode;
|
||||
} else {
|
||||
temp = NULL;
|
||||
}
|
||||
@@ -17,7 +17,7 @@ void insert(bookList *l) {
|
||||
int main() {
|
||||
bookList books = new bookNode;
|
||||
books->next = NULL;
|
||||
insert(&books);
|
||||
insert(books);
|
||||
display(&books);
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user