基于链式存储结构的图书信息表的旧图书的出库
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
//#pragma warning(disable:)
using namespace std;
struct information {
char booknum[20];
char bookname[20];
float price = 0.0f;
};
typedef struct LNode {
information data;
LNode *next;
}*Linklist;
void Create(Linklist &L, int *num) {
L = new LNode;
Linklist p, r;
p = new LNode;
L->next = p;
cout << "请输入图书信息" << endl;
while (1) {
cin >> p->data.booknum >> p->data.bookname >> p->data.price;
if (p->data.booknum == 0 || p->data.bookname == 0 || p->data.price == 0) {
break;
}
r = p;
p = new LNode;
r->next = p;
(*num)++;
}
p->next = NULL;
}
int Comeout(Linklist &L, int *num, int *place) {
Linklist p, u,fore=new LNode;
p = L;
if (*place > *num || *place <= 0) {
return 0;
}
else {
while (*place) {
fore = p;
p = p->next;
(*place)--;
}
u = p;
fore->next = p->next;
delete u;
return 1;
}
}
void output(Linklist &L, int *num) {
Linklist r = L->next;
while (r->data.price) {
cout << r->data.booknum << " " << r->data.bookname << " " << r->data.price << endl;
r = r->next;
(*num)--;
}
}
int main() {
Linklist L; int num = 0,place=0;
cout << "请输入图书本数" << endl;
scanf_s("%d", &num);
Create(L, &num);
cout << "请输入出库位置" << endl;
scanf_s("%d", &place);
if (!Comeout(L, &num, &place)) {
cout << "抱歉出库位置非法" << endl;
}
else {
output(L, &num);
}
system("pause");
return 0;
}#include<stdio.h>
#incl