| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 503 人关注过本帖
标题:单向链表的取值问题
只看楼主 加入收藏
hangeng
Rank: 2
等 级:论坛游民
帖 子:424
专家分:39
注 册:2007-7-23
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:2 
单向链表的取值问题
/*************
*权重计算
************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
const char END[10]="end";
typedef struct weight
{
    weight   *next;
    char thing[10];
    int  weightnumber;

};


int main()
{
    char  str[10];
    printf("\t\t权重分析程序 \n");
    printf("\t\t\t\t\t版本:1.0.0.0430\n");
   



    weight  *head,*right,*copy;


    head=(weight   *) malloc (sizeof(weight));
    right=head;

    printf("请输入第一个权重项目");
    scanf("%s",str);
    strcpy(str,head->thing);



    if(NULL!=right)
    {
        printf("输入end结束输入");
    }

    while(0!=strcmp(str,END))
    {
        right=(weight   *) malloc (sizeof(weight));
        strcpy((*right).thing,str);
        (*right).next=right;

        //text
        printf("%d",right);

        printf("请输入下一项名称");
        scanf("%s",str);
        printf("您输入的名称是%s",str);
        
    }
    right->next=NULL;//链表结尾置空

    printf("输入完成,接下来进行比较,如果您认为第一项比第二项重要则输入1,否则输入0。");
    printf("第一项\t\t\t 第二项");

    right=head;//重置链表头结点
    copy=head;
    while(copy->next !=NULL)
    {
   
        while(right!=NULL)
        {
        printf("%s\t\t\t%s",(*right).thing,(*copy).thing);
        scanf("%d",&right->weightnumber);
        right->weightnumber=right->weightnumber+1;
        right=right->next;
        }
        right=head;
        copy=copy->next;
    }


    return 0;
}
红色处有问题
但是程序无法正常运行
搜索更多相关主题的帖子: 链表 
2010-05-02 07:33
dmee
该用户已被删除
收藏
得分:15 
提示: 作者被禁止或删除 内容自动屏蔽
2010-05-02 09:07
南国利剑
Rank: 12Rank: 12Rank: 12
等 级:贵宾
威 望:29
帖 子:1165
专家分:3536
注 册:2010-4-12
收藏
得分:5 
请楼主说清楚是编译就过不了,还是运行时出现问题?
如果是后者的话,那很有可能是你节点的指向出来问题。

南国利剑
2010-05-03 20:06
快速回复:单向链表的取值问题
数据加载中...
 
   



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

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