Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2509920
  • 博文数量: 308
  • 博客积分: 5547
  • 博客等级: 大校
  • 技术积分: 3782
  • 用 户 组: 普通用户
  • 注册时间: 2009-11-24 09:47
个人简介

hello world.

文章分类

全部博文(308)

分类: C/C++

2010-08-27 14:42:24

    链表元素删除:

struct student *del(struct student *head,long num)
{
       struct student *p1,*p2;
       if (head == NULL)
       {
          printf("list is NULL!\n");
          return head;
       }
       p1 = head;
       while(num != p1->num && p1->next != NULL)
       {
           p2 = p1;
           p1 = p1->next;
       }
       if (num == p1->num)
       {
          if (p1 == head)
          {
             head = p1->next;
          }
          else
          {
              p2->next = p1->next;
          }
          printf("delete :%ld\n",num);
          n -= 1;
       }
       else
       {
           printf("%ld not been found!\n",num);
       }
       return head;
}


阅读(677) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~