c语言仓库管理系统链表,仓库管理系统 C语言 C++ 数据结构 链表 课程设计
倉庫管理系統 C語言 C++ 數據結構 鏈表 課程設計
#include
#include
#include
#include
#define MAX 64
typedef struct node{ /* 定義結構體類型dnode */
int number; /* 貨物編號 */
char name[MAX]; /* 貨物名稱 */
int counter; /* 貨物數量 */
struct node *prior,*next; /* 前驅和后繼指針 */
}dnode;
dnode* head = NULL;
void output_one(dnode* n)/* 輸出一條記錄 */
{
printf("%d\t%s\t%d\n", 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->prior = 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->prior->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;
}
void init()
{
while (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->next)
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,就刪除 */
{
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;
}
retu
總結
以上是生活随笔為你收集整理的c语言仓库管理系统链表,仓库管理系统 C语言 C++ 数据结构 链表 课程设计的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: ios上编译c语言的app,iOS Ap
- 下一篇: ds18b20温度传感器 lcd C语言