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

hello world.

文章分类

全部博文(308)

分类: C/C++

2010-08-27 14:43:24

    链表元素插入:
 

struct student *insert(struct student *head,struct student *stu)
{
       
       struct student *p0,*p1,*p2;
       p1 = head;
       p0 = stu;
       if(NULL == head)
       {
               head = p0;
               p0->next = NULL;
               
       }
       else
       {
           while (p0->num > p1->num && p1->next != NULL)
           {
                 p2 = p1;
                 p1 = p1->next;
           }
           if (p0->num <= p1->num)
           {
              if (p1 == head)
              {
                 head = p0;
              }
              else
              {
                  p2->next = p0;
              }
              p0->next = p1;
           }
           else
           {
               p1->next = p0;
               p0->next = NULL;
           }
       }
       n += 1;
       return head;
}


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