| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 700 人关注过本帖
标题:[求助]检查这程序,大家讨论下?
只看楼主 加入收藏
monks1986
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2006-12-26
收藏
 问题点数:0 回复次数:1 
[求助]检查这程序,大家讨论下?

建立一个小型信息管理系统(可以是图书、人事、学生、物资、商品等任何信息管理系统)。
要求:
1 使用哈希查找表存储信息;
2 实现查找、插入、删除、统计、输出等功能;
3 尝试使用多种哈希函数和冲突解决方法,
#include "stdio.h"
#define NULL 0
typedef struct node{
int price;
int num;
struct node *next;
}TVStorage;
void CreateList(TVStorage *h)/*初始化链表(输入电视机价格、台数),以0为结束符,并以升序打印*/
{TVStorage *q,*r,*p;
r=(TVStorage*)malloc(sizeof(TVStorage));
printf("\nCreate List as follows:");
printf("\nInput price,num:");
scanf("%d,%d",&r->price,&r->num);
r->next=NULL;
while(r->price!=0)
{q=h;p=h->next;
if(p==NULL) h->next=r;
else {while ((r->price>p->price)&&(p->next!=NULL))
{q=p;p=p->next;}
if (r->price<p->price)
{r->next=p;q->next=r;}
else if(r->price==p->price)(p->num)=(p->num)+(r->num);
else {p->next=r;r->next=NULL;}
}
r=(TVStorage*)malloc(sizeof(TVStorage));
printf("\nInput price,num:");
scanf("%d,%d",&r->price,&r->num);
}
}
void Intostore(TVStorage *h)/*电视机入库(输入电视机价格、台数),以0为结束符,并以升序打印*/
{TVStorage *q,*r,*p;
r=(TVStorage*)malloc(sizeof(TVStorage));
printf("\nInput intostore's price,num:");
scanf("%d,%d",&r->price,&r->num);
r->next=NULL;
while(r->price!=0)
{q=h;p=h->next;
if(p==NULL) h->next=r;
else {while ((r->price>p->price)&&(p->next!=NULL))
{q=p;p=p->next;}
if (r->price<p->price)
{r->next=p;q->next=r;}
else if(r->price==p->price) (p->num)=(p->num)+(r->num);
else {p->next=r;r->next=NULL;}
}
r=(TVStorage*)malloc(sizeof(TVStorage));
printf("\nInput intostore's price,num:");
scanf("%d,%d",&r->price,&r->num);
}
}

Outstore(TVStorage *h)/* 电视机出库(输入电视机价格、台数),以0为结束符,并以升序打印*/
{ TVStorage *q,*r,*p;
r=(TVStorage*)malloc(sizeof(TVStorage));
printf("\nInput outstore's price,num:");
scanf("%d,%d",&r->price,&r->num);
while(r->price!=0)
{q=h;p=h->next;
while ((r->price!=p->price)&&(p->next!=NULL))
{q=p;p=p->next;}
if (r->price==p->price)
{while (r->num>p->num)
{printf("\n Outstore's num is more,please choose:\n");
printf(" A.Input again----choose 'A'or'a'\n");
printf(" B.Outstore as the-most-storage %dsets---choose any key\n",p->num);
printf(" please choose:");
if(getchar()=='A'||getchar()=='a')
{printf("\nInput num again:");
scanf("%d",&r->num);}
else {printf("Outstore as the most storage %d\n",p->num);
r->num=p->num;}
}
p->num=p->num-r->num;
if(p->num==0) {q->next=p->next;free(p);}
}
else printf("Outstore's price isn't exists,please input again.\n");
r=(TVStorage*)malloc(sizeof(TVStorage));
printf("\nInput outstore's price,num:");
scanf("%d,%d",&r->price,&r->num);
}
}

void Search(TVStorage *h)/*根据价格查询库存台数,以0为结束符,并输出相应台数*/
{ TVStorage *p,*q;
int Schprice;
printf("\nplease input search's price:");
scanf("%d",&Schprice);
while(Schprice!=0)
{ q=h;p=q->next;
while(p->price!=Schprice&&p->next!=NULL)
{q=p;p=p->next;}
if(p->price==Schprice)
printf("\nthe price %d is %d sets.\n",Schprice,p->num);
else printf("\nsearch's price isn't exist,please input again.\n");
printf("\nplease input search's price:");
scanf("%d",&Schprice);}
}
void PrintList(TVStorage *h) /*打印电视机的价格和台数*/
{TVStorage *p;
p=h->next;
printf("TVStorage as follow:(Sort Ascending of price)\n\n");
printf(" TV price Storage\n\n");
while(p!=NULL)
{printf("%10dyuan%10dsets\n",p->price,p->num);
p=p->next;}
}

main() /*主函数体部分*/
{TVStorage *head,*p;
int c;
head=(TVStorage*)malloc(sizeof(TVStorage));
head->next=NULL;
CreateList(head);
PrintList(head);
do{
printf("\nThe system provides as follow's function:\n");
printf(" 1.Tv Intostore\n");
printf(" 2.Tv Outstore\n");
printf(" 3.Storage Search\n");
printf(" 4.Exit\n");
printf("Please choose 1,2,3,4:");
scanf("%d",&c);
switch(c)
{ case 1:Intostore(head);printf("\nAfter intostore,");PrintList(head);break;
case 2:Outstore(head);printf("\nAfter outstore,");PrintList(head);break;
case 3:Search(head);break;
case 4:printf("See you later !\n");break;
default:printf("error,please choose again\n");
}
}
while(c!=4);
}

看到请快提意见谢谢

搜索更多相关主题的帖子: 信息管理系统 电视机 TVStorage 哈希 
2007-04-17 13:03
天下第二刀
Rank: 3Rank: 3
等 级:新手上路
威 望:8
帖 子:157
专家分:0
注 册:2007-1-8
收藏
得分:0 

结构 ,注释


不知天堂有没有后门~~~
2007-04-17 18:46
快速回复:[求助]检查这程序,大家讨论下?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.021120 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved