爱问知识人 爱问教育 医院库

链表结点插入

首页

链表结点插入

程序首先完成创建两链表,要求补充完成按学号顺序插入链表结点的函数

请用C语言

提交回答

全部答案

    2008-06-01 00:21:06
  •   #include
    #include
    #define len sizeof(struct stu)
    struct stu
    {   long num;
        struct stu *next;
    };
    struct stu *head;
    void insert(void);       /*插入链表节点函数*/
    void main(void)
    {   long a;
        struct stu *p,*q;
        p=(struct stu*)malloc(len);
        head=p;
        head->next=NULL;
        q=(struct stu*)malloc(len);
        printf("Please enter number:");
        scanf("%ld",&a);
        while(a!=0)          /*创建链表,假设学号是按顺序输入*/
        {   p->next=q;
            p=q;
            p->num=a;
            q=(struct stu*)malloc(len);
            printf("Please input number:");
            scanf("%ld",&a);
         }
         p->next->next=NULL;
         insert();
         getch();
    }
    void insert(void)
    {   long a;
        struct stu *p,*q;
        printf("Please enter number:");
        scanf("%ld",&a);
        p=head;
        while(p->next!=NULL && p->next->numnext;
        }
        q->next=p->next;
        p->next=q;
        q->num=a;
    }
     。
      

    天***

    2008-06-01 00:21:06

类似问题

换一换
  • C/C++ 相关知识

  • 电脑网络技术
  • 电脑网络

相关推荐

正在加载...
最新资料 推荐信息 热门专题 热点推荐
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200

热点检索

  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 176-195
返回
顶部
帮助 意见
反馈

确定举报此问题

举报原因(必选):