| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 796 人关注过本帖
标题:建立链表哪里出现问题了,求解,谢谢
只看楼主 加入收藏
henyue
Rank: 1
等 级:新手上路
帖 子:36
专家分:0
注 册:2006-6-3
收藏
 问题点数:0 回复次数:2 
建立链表哪里出现问题了,求解,谢谢
//建立双向循环链表                                                     
void create_d_list ( struct d_list **headp, int *p )                                                                                                                                                                  
{                                                               
   struct d_list *head = NULL, *tail;                              
   if( p[0] == 0 )                                                     
   *headp = NULL;                                                   
   else
   {                                                           
      head = ( struct d_list * ) malloc ( sizeof( struct d_list ) );            
      //head->data = *p++;   
      head->data = *p;                                             
      tail = head;
      printf("head->data=%d\n",head->data);                                                
      while( *p )
      {                                                      
         tail->next = ( struct d_list * ) malloc ( sizeof ( struct d_list ) );      
         tail->next->prior = tail;   
         //tail = head->prior; //                                    
         //tail = tail->next;   
         head = tail->next;    //                                         
         tail->data = *p++;                                                
      }
      printf("tail->data=%d\n",tail->data);                          
      tail->next = head;                                                
      head->prior = tail;                                             
   }                     
   *headp = head;                                                   
}

[[it] 本帖最后由 henyue 于 2008-8-15 15:49 编辑 [/it]]
搜索更多相关主题的帖子: 链表 求解 list headp struct 
2008-08-15 15:25
殇雪
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2007-6-21
收藏
得分:0 
“while( *p )
      {                                                      
         tail->next = ( struct d_list * ) malloc ( sizeof ( struct d_list ) );      
         tail->next->prior = tail;   
         //tail = head->prior; //                                    
         //tail = tail->next;   
         head = tail->next;    //                                         
         tail->data = *p++;                                                
      }

把"   head = tail->next;    //                                         "  换成“tail=tail->next”  试下,      


 另外,  while(*p)  这个判断法肯定有问题

2008-08-15 16:33
henyue
Rank: 1
等 级:新手上路
帖 子:36
专家分:0
注 册:2006-6-3
收藏
得分:0 
那应该怎么改呢,可以说下吗
2008-08-15 16:49
快速回复:建立链表哪里出现问题了,求解,谢谢
数据加载中...
 
   



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

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