Hello, 大家好,我是爱吃香蕉的猴子,写写链表
// goodsManager.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
#include <iostream>
using namespace std;
class Goods
{
public:
Goods()
{
weight = 0;
next = NULL;
cout << "创建一个重量为" << weight << "的货物" << endl;
}
~Goods()
{
//仓库减少这个货物的重量
}
Goods(int w)
{
//需要创建一个w的货物,并且仓库加上这个重量
}
Goods* next; //
private:
int weight; //重量
static int tatal_weight;//总重量
};
int Goods::tatal_weight = 0;//static 立马初始化
void buy(Goods * &head, int w)
{
//创建一个货物 重量是w
Goods* new_goods = new Goods(w);
if (head == NULL) {
head = new_goods;
}
else {
new_goods->next = head;//在之前的head前插入
head = new_goods;
}
}
void sale(Goods * &head) {//需要的是指针变量指向的内容 *head: 指针 head:指针变量
if (head == NULL) {
cout << "仓库中已经没有货物了..." << endl;
return;
}
Goods* temp = head;
head = head ->next;
delete temp;
cout << "saled" << endl;
}
int main()
{
int choice = 0;
int w = 0;
Goods* head = NULL;
do {
cout << "1 进货" << endl;
cout << "2 退货" << endl;
cout << "0 退出" << endl;
cin >> choice;
switch (choice) {
case 1:
//进货
cout << "请输出要创建货物的重量" << endl;
cin >> w;
buy(head, w);
break;
case 2:
//出货
break;
case 0:
//退出
break;
default:
break;
}
} while (1);
}
Code的搬运工V1.0