《仓库管理系统 C语言 C++ 数据结构 链表 课程设计.docx》由会员分享,可在线阅读,更多相关《仓库管理系统 C语言 C++ 数据结构 链表 课程设计.docx(12页珍藏版)》请在三一办公上搜索。
1、仓库管理系统 C语言 C+ 数据结构 链表 课程设计#include <stdio.h>#include <stdlib.h>#include <string.h>#include <conio.h>#define MAX 64typedef struct node /* 定义结构体类型dnode */int number; /* 货物编号 */char nameMAX; /* 货物名称 */int counter; /* 货物数量 */struct node *prior,*next; /* 前驱和后继指针 */dnode;dnode* head = NULL
2、;void output_one(dnode* n)/* 输出一条记录 */printf(%dt%st%dn, n->number, n->name, n->counter);void output/* 输出所有记录 */dnode* pos = head;if(head = NULL)return;while (pos)output_one(pos);/* 循环调用output_one */pos = pos->next;int insert/* 插入一条数据 */dnode* pos = head;dnode* n = malloc(sizeof(dnode);n->p
3、rior = NULL;n->next = NULL;printf(请输入货物编号:);scanf(%d, &n->number);printf(请输入货物名称:);scanf(%s, n->name);printf(请输入货物数量:);scanf(%d, &n->counter);if(head=NULL)/* 如果还没有头节点,就作为头节点 */head = n;return 1;while (pos)if(pos->number > n->number)/* 按顺序查找,如果找到比自己大的,就插在它前面 */if(pos->prior)pos->pri
4、or->next = n;n->prior = pos->prior;pos->prior = n;if(pos->next)pos->next->prior = n;n->next = pos;return 1;else if(pos->number = n->number)free(n);return 0;/* 有重复数据,插入不成功 */if (!pos->next)/* 如果已经到链表尾部,插入到后面 */pos->next = n;n->prior = pos;return 1;pos = pos->next;return 1;
5、void initwhile (1)/* 初始化,循环插入 */insert;printf(按任意键继续输入,按Esc停止输入n);if(getch=27)break;int delete/* 删除一条记录 */int num;dnode* pos = head;printf(请输入要删除的编号:);scanf(%d, &num);if(head = NULL)return 0;while (pos)if(pos->number = num)/* 找到匹配的项 */if(pos->prior)pos->prior->next = pos->next;if(pos->ne
6、xt)pos->next->prior = pos->prior;free(pos);return 1;pos = pos->next;return 0;/ 没找到int amend/* 修改数量 */int num, count;dnode* pos = head;printf(请输入要修改的编号:);scanf(%d, &num);printf(请输入要修改的数量:);scanf(%d, &count);if(head = NULL)return 0;while (pos)if(pos->number = num)if (count = 0)/* 如果数量是0,就删除
7、*/if(pos->prior)pos->prior->next = pos->next;if(pos->next)pos->next->prior = pos->prior;free(pos);return 1;pos->counter = count;return 1;pos = pos->next;return 0;void search/* 按编号查找 */int num;dnode* pos = head;printf(请输入要查找的编号:);scanf(%d, &num);if(head = NULL)return;while (pos)if
8、(pos->number = num)output_one(pos);/* 找到就打印 */return;pos = pos->next;void search_by_name/* 按名称查找 */char nameMAX;dnode* pos = head;printf(请输入要查找的名称:);scanf(%s, name);if(head = NULL)return;while (pos)if(!strcmp(pos->name, name)output_one(pos);pos = pos->next;int maininit;while (1)char ch;syste
9、m(cls);printf(tttti 增加新货物n);printf(ttttd 删除某种货物n);printf(tttta 修改某种货物的数量n);printf(tttts 查找指定的货物n);printf(tttto 输出存货信息n);printf(ttttq 退出程序n);ch = getch;switch (ch)case i:case I:insert;break;case d:case D:delete;break;case a:case A:amend;break;case s:case S:printf(1. 按编号查找n2. 按名称查找n);ch = getch;if(ch = 1)search;else if(ch = 2)search_by_name;break;case o:case O:output;break;case q:case Q:return 0;break;printf(按任意键继续.n);getch;return 0;