| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 682 人关注过本帖
标题:链表删除问题?
取消只看楼主 加入收藏
想你的天空
Rank: 2
等 级:新手上路
威 望:5
帖 子:610
专家分:0
注 册:2004-12-30
收藏
 问题点数:0 回复次数:0 
链表删除问题?
#include"stdio.h"
 typedef struct node
  {  int data;
     struct node *next;
  }NODE;
  int x,i;
  NODE *creat()
 {  NODE *head,*p,*s;
    int x;
    head=(NODE*)malloc(sizeof(NODE));
    p=head;
    printf("输入整数,以0标志结束\n");
    scanf("%d",&x);
    while(x!=0)
   {  s=(NODE*)malloc(sizeof(NODE));
      s->data=x;
      p->next=s;
      s->next=NULL;
      p=s;
      scanf("%d",&x);
   }
   p->next=NULL;
   p=head;
   head=head->next;
   free(p);
   return head;
 }
 void delete(head,x)
 {  NODE *head,*p,*q;
   if(head==NULL) printf("链表下益\n");
   if(head->data==x)
   { p=head;
     head=head->next;
     free(p);
   }
   else
   { q=head; p=head->next;
     while(p!=NULL&&p->data!=x)
      if(p->data!=x)
      { q=p;p=p->next;
      }
      if(p!=NULL)
      { q->next=p->next;
        free(p);
      }
      else printf("没找到\n");
   }
 }
 main()
 {  NODE *head,*p;
    head=creat();
    while(p!=NULL)
    { printf("%d",p->data);
      p=p->next;
    }
   printf("输入要删除的节点:");
   scanf("%d",&x);
   delete(head,x);
    p=head;
    while(p!=NULL)
    { printf("%d",p->data);
      p=p->next;
    }  
 }    //谁能调通这个程序啊?
搜索更多相关主题的帖子: 链表 NODE head next 
2005-03-28 14:00
快速回复:链表删除问题?
数据加载中...
 
   



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

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