| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1291 人关注过本帖
标题:困扰我一星期的数据链表的问题
只看楼主 加入收藏
gyu130
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2008-6-10
收藏
 问题点数:0 回复次数:5 
困扰我一星期的数据链表的问题
困扰我一星期的数据链表的问题
源码如下:
#include <stdlib.h>
#include <stdio.h>

struct node
{
    int d[5];
    struct node *next;
};

struct node  *lookst(struct node *head,int x)                   //&sup2;é&Otilde;&Ograve;
{
struct node *p;
p=head;
while((p->next!=NULL)&&((p->next)->d[5])!=x)p=p->next;
return(p);        
}
   
inslst(struct node **head,int x,int b)                          //&sup2;&aring;&Egrave;&euml;
{
    struct node *p,*q ;
    p=(struct node *)malloc(sizeof(struct node));
    p->d[5]=b;
    if(*head==NULL)
        {
            *head=p;
            p->next=NULL;
            return 0;
            }
    if((*head->d[5])==x)
    {
        p->next=*head;
        *head=p;
        return 0;
        }
    q=lookst(*head,x);
    p->next=q->next;
    q->next=p;
    return 0;
    }
   
delst(struct node **head,int x)
{
struct node *p,*q;
if(*head==NULL)
    {
    printf("This is a empty list !\n");   
    return 0;
    }   
if((*head->d[5])==x)
    {
    p=*head->next;
    free(*head);
    *head=p;
    return 0;   
    }   
q=lookst(*head,x);
if(q->next==NULL)
    {
    printf("No this node in the list!\n");
    return 0;   
    }
p=q->next;q->next=p->next;
free(p);   
return 0;
}



main()
  {
        int i,n,d[5];
        struct node *m;
        printf("the input number:\n");
        for(i=0;i<5;i++)
        scanf("%d",&d[i]);
        printf("\n");
        printf("please input the insert number:\n");
        scanf("%d",&n);
        lookst(m,4);
        inslst(&m,3,5);
        for(i=0;i<6;i++)
        printf("%d",&d[i]);
        delst(&m,5);
        for(i=0;i<6;i++)
        printf("%d",&d[i]);
    }


以上程序编译报错:
C:\Documents and Settings\dell\×&Agrave;&Atilde;&aelig;\data\4.c(29) : error C2223: left of '->d' must point to struct/union
C:\Documents and Settings\dell\×&Agrave;&Atilde;&aelig;\data\4.c(49) : error C2223: left of '->d' must point to struct/union
C:\Documents and Settings\dell\×&Agrave;&Atilde;&aelig;\data\4.c(51) : error C2223: left of '->next' must point to struct/union
不知如何解决,希望高人指点哈!
搜索更多相关主题的帖子: 链表 困扰 数据 
2008-10-22 22:37
swsun000
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2008-10-22
收藏
得分:0 
先顶你!
2008-10-23 11:02
zhengfans
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2008-10-9
收藏
得分:0 
#include <stdlib.h>
#include <stdio.h>

struct node
{
    int d[5];
    struct node *next;
};

struct node  *lookst(struct node *head,int x)                   //2é?ò
{
struct node *p;
p=head;
while((p->next!=NULL)&&((p->next)->d[5])!=x)p=p->next;
return(p);        
}
   
void inslst(struct node **head,int x,int b)                          //2?è?
{
    struct node *p,*q ;
    p=(struct node *)malloc(sizeof(struct node));
    p->d[5]=b;
    if(*head==NULL)
        {
            *head=p;
            p->next=NULL;
           // return 0;
            }
    if(((*head)->d[5])==x)
    {
        p->next=*head;
        *head=p;
       // return 0;
        }
    q=lookst(*head,x);
    p->next=q->next;
    q->next=p;
   // return 0;
    }
   
void delst(struct node **head,int x)
{
struct node *p,*q;
if(*head==NULL)
    {
    printf("This is a empty list !\n");   
   // return 0;
    }   
if(((*head)->d[5])==x)
    {
    p=(*head)->next;
    free(*head);
    *head=p;
    //return 0;   
    }   
q=lookst(*head,x);
if(q->next==NULL)
    {
    printf("No this node in the list!\n");
    //return 0;   
    }
p=q->next;q->next=p->next;
free(p);   
//return 0;
}



main()
  {
        int i,n,d[5];
        struct node *m;
        printf("the input number:\n");
        for(i=0;i<5;i++)
        scanf("%d",&d[i]);
        printf("\n");
        printf("please input the insert number:\n");
        scanf("%d",&n);
        lookst(m,4);
        inslst(&m,3,5);
        for(i=0;i<6;i++)
        printf("%d",&d[i]);
        delst(&m,5);
        for(i=0;i<6;i++)
        printf("%d",&d[i]);
    }
2008-10-23 20:48
nuciewth
Rank: 14Rank: 14Rank: 14Rank: 14
来 自:我爱龙龙
等 级:贵宾
威 望:104
帖 子:9786
专家分:208
注 册:2006-5-23
收藏
得分:0 
就是说->的左边不是个指针

倚天照海花无数,流水高山心自知。
2008-10-23 21:01
hds742
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2008-10-18
收藏
得分:0 
你定义的数组长度为5,你D[5]啥意思??过错了吧
2008-10-23 21:26
gyu130
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2008-6-10
收藏
得分:0 
明白了啊,谢谢了!
2008-10-24 22:21
快速回复:困扰我一星期的数据链表的问题
数据加载中...
 
   



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

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