高分求高手解答

Recall_ani 2009-07-16 04:36:36
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define MAXSIZE 10
typedef struct{
char name[MAXSIZE];
char model[MAXSIZE];
float price;
int quantity;
}Lnode;

typedef struct Node{
Lnode data;
struct Node *next;
}Linklist;

Linklist *init_list()
{
Linklist *l;
l=(Linklist *)malloc(sizeof(Linklist));
if(l==NULL)
printf("空间分配失败");
l->next=NULL;
return(l);

}//链表的初始化

Linklist *creat_list(Linklist *l,int m)
{
Linklist *p,*q=NULL;
p=l;
int i;
for(i=m;i>0;i--)
{
q=(Linklist *)malloc(sizeof(Linklist));
printf("请输入家电名称:");
scanf("%s",p->data.name);
getchar();
printf("请输入家电类型:");
scanf("%s",p->data.model);
getchar();
printf("请输入家电现在单价:");
scanf("%f",&p->data.price);
getchar();
printf("请输入现有家电数量:");
scanf("%d",&p->data.quantity);
getchar();
q->next=NULL;
p->next=q;
p=q;
q=q->next;
}
return l;
}//链表的创建


int sorting(Linklist *l,int m)
{
int i=1,j=0,n;
Linklist *p,*q=NULL,*r=NULL;
p=l;
while(i!=0)
{
i=0;
for(j=1;j<m+1;j++)
for(n=1;n<m+1-j;n++)
{
q=p->next;
r=q->next;
if(r==NULL)
{
i++;
break;
}
if(q->data.price>r->data.price)
{
q->next=r->next;
p->next=r;
r->next=q;
i++;
}
p=p->next;
}
}
return 1;
}//链表中元素的排序


void print(Linklist *l)
{
Linklist *p=l;
if(p==NULL)
{
printf("没有可以打印的数据!\n");
return;
}
while(p->next!=NULL)
{
printf("家电名称:%s\n",p->data.name);
printf("家电类型:%s\n",p->data.model);
printf("家电现在单价:%f\n",p->data.price);
printf("家电现有数量:%d\n",p->data.quantity);
p=p->next;
printf("\n");
}
}//链表中元素的打印

void main()
{
system("color 3e");
Linklist * head=NULL;
int m,n;
menu();
head=init_list();
printf("请输入所有家电的品牌,型号,单价和现有数量:");
scanf("%d",&m);
getchar();
creat_list(head ,m);
sorting(head,m);
print(head);
}

是用C语言写的,用的是VC++6.0编译器
...全文
39 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
爱摸鱼de老邪 2009-07-16
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 Recall_ani 的回复:]
不会呀!那个大循环每次执行的时候都要使i置0啊!
[/Quote]
是啊,大循序是置0了,但是你又得去重新执行那个for双重循环,i值又不为0了,呵呵
Recall_ani 2009-07-16
  • 打赏
  • 举报
回复
不会呀!那个大循环每次执行的时候都要使i置0啊!
ShowMan 2009-07-16
  • 打赏
  • 举报
回复
死循环了吧, i++是不是一直要被执行。
Recall_ani 2009-07-16
  • 打赏
  • 举报
回复
程序运行到排序那里就停止了
liao05050075 2009-07-16
  • 打赏
  • 举报
回复
什么问题?
Recall_ani 2009-07-16
  • 打赏
  • 举报
回复
高手进门!!!!!!

69,382

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧