【发布时间】:2014-06-22 14:49:21
【问题描述】:
这是我的代码
struct Node{
char* isbn;
char* author;
char* title;
char* copyright;
char* genre;
bool status;
Node* next;
};
struct LinkedList {
Node* head; // This is the starting pointer of Linked List
LinkedList(){
head = NULL;
}
void insertAtHead(char* a, char* b, char* c, char* d, char* e, bool f){
Node* temp = new Node;
temp->isbn = a;
// etc. assigning information
temp->next = head;
head = temp;
}
void display(){
int i = 1;
Node* it = head;
while (it != NULL){
// display book info
it = it->next;
i++;
}
cout << "\n";
}
};
int main(){
LinkedList LL;
int x;
char a1[10] = "";
char a2[25] = "";
char a3[25] = "";
char a4[15] = "";
char a5[15] = "";
bool a6 = 0;
do{
cout << "\n======================================\n";
cout << "1) Insert Book At Head.\n";
cout << "2) Display All Books.\n";
cout << "3) Exit.\n";
cout << "======================================\n";
cin >> x;
switch(x){
case 1:{
cout << "Enter ISBN: "; cin >> a1;
cout << "Enter The Author's Name: "; cin >> a2;
cout << "Enter The Book Title: "; cin >> a3;
cout << "Enter The CopyRights: "; cin >> a4;
cout << "Enter The Book Genre: "; cin >> a5;
cout << "Enter The Status Of Book: "; cin >> a6;
LL.insertAtHead(a1,a2,a3,a4,a5,a6);
break;
}
case 2:
LL.display();
break;
case 3:
break;
}
}while(x!=3);
return 0;
}
问题是,当我使用 switch 的案例 1 插入一本书时,它会插入一本书 具有给定数据的链接列表,但是当我输入新书时,以前保存的书 被新书覆盖了
【问题讨论】:
标签: c++ linked-list