There are already a, a, a, two linked lists, each of which includes the number of points, scores. The two linked lists are required to be merged in ascending order by the number of studies.

Source: Internet
Author: User

#include  <stdio.h> #include  <stdlib.h> #define  N 10typedef struct  student{    int num;    float score;     Struct student *next;} Stu;stu *creat () {    int i;    stu *p,*head =  NULL,*tail = head;    for  (i = 0; i < n;  i++)     {        p =  (stu *) malloc (sizeof (STU)); &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;SCANF ("%d%f",&p->num,&p-> Score);        p->next = null;         if  ( p->num <= 0)          {            free (p);             break;        }         if (head == null)              head = p;        else             tail->next = p;         tail = p;    }     Return head;} Void print (stu *p) {    while  (p != null)     {         printf ("%d\t%.2f\n", P->num,p->score);         p = p->next;    }}stu *link (STU&NBSP;*P1, STU&NBSP;*P2) {    stu *p,*head;    if  ( p1->num  < p2->num )      {        head  = p = p1;        p1 = p1->next;     }    else    {         head = p = p2;        p2 =  p2->next;    }    while  (  (p1 != null)  &&  (p2 != null )     {         if  (P1->num < p2->num)          {            p->next = p1;             p = p1;             p1 = p1->next;        }         else        {             p->next = p2;             p = p2;             p2 = p2->next;        }     }    if (p1 != null)          P->next = p1;    else        p-> Next = p2;    return head;} Int main ()  {    stu *a,*b,*c;    printf ("\ n Please enter the information for List A, School number is less than or equal to 0 o'clock end input: Format (school number   score) \ n ");     a = creaT ();     printf ("\ n Please enter the information for link list B, the number is less than or equal to 0 o'clock end input: Format (school number   score) \ n");     b  = creat ();     printf ("\ nthe information for List A: \ n");     print (a);     printf ("\ nthe information for List B is: \ n");     print (b);     c =  link (A, b);     printf ("\ n" linked list information: \ n ");     print (c);     return 0;}


There are already a, a, a, two linked lists, each of which includes the number of points, scores. The two linked lists are required to be merged in ascending order by the number of studies.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.