#include<bits/stdc++.h>
using namespace std;
#define ISBN_LENGTH 13
#define NAME_LENGTH 20
#define PRESS_LENGTH 20
#define AUTHOR_LENGTH 20
typedef struct{
char book_number[ISBN_LENGTH];
char book_name[NAME_LENGTH];
char pub_press[PRESS_LENGTH];
char author_name[AUTHOR_LENGTH];
double book_price;
}Book;
struct List{
Book data;
struct List* next;
};
bool initList(List** p){
*p=(List*)malloc(sizeof(List));
if(*p==NULL)return 0;
(*p)->next=NULL; return 1;
}
bool insertList(List* it,Book tBook){
while(it->next!=NULL){it=it->next;}
it->next=(List*)malloc(sizeof(List));
it->next->data=tBook; it->next->next=NULL;
return 1;
}
bool deleteItem(List* it,char* ISBN){
do{
if(strcmp(ISBN,it->data.book_number)==0){
while(it->next!=NULL)it=it->next; free(it);
return 1;
}
it=it->next;
}while(it!=NULL);
return 0;
}
void displayList(List* it){
int i = 0;it = it->next;
do{
Book& p = it->data;
printf("[ID#%d %s %s %s %s %lf]\n",i+1,p.book_number,p.book_name,
p.pub_press,p.author_name,p.book_price);
it=it->next;
}while(it!=NULL);
}
int main(){
List *it; Book tBook; char ch; int cnt=0; initList(&it);
do{
cout<<"#DATA Format: book_number(str) book_name(str) pub_press(str) author_name(str) book_price(double)"<<endl;
cout<<"[INPUT]>>>";
cin>>tBook.book_number>>tBook.book_name>>tBook.pub_press
>>tBook.author_name>>tBook.book_price;getchar();
if(!insertList(it,tBook)){cerr<<"INSERT ERROR";return 0;};
cout<<"[Notice]Push Y/y for continue,others for break."<<endl;
cout<<"[INPUT]>>>";
ch=getchar();
}while(ch=='Y'||ch=='y');
#define TEST_DEL
#define TEST_DEL
char ISBN[ISBN_LENGTH];
cin>>ISBN;
deleteItem(it,ISBN);
displayList(it);
#define endif
return 0;
}