c语言仓库管理系统链表,仓库管理系统 C语言 C 数据结构 链表 课程设计.doc

仓库管理系统 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(

  • 0
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值