本帖最后由 oyljerry 于 2011-05-05 22:17:50 编辑

解决方案 »

  1.   


    struct Chain * creat()
    {
    int temp;
    struct Chain *head = NULL;
    printf("请输入链表各结点值(非数字字符表示结束):\n");
    while (scanf("%d", &temp))
    {
    p1 = new struct Chain;
    p1->num = temp;
    if (head == NULL)
    {
    head = p1;
    p1->next = NULL;
    }
    else

    if (temp < head->num)
    {
    p1->next = head;
    head = p1;
    }
    else
    {
    p2 = head;
    while (p2->next != NULL)
    {
    if ( temp >= p2->num && temp < p2->next->num)
    {
    p3 = p2->next;
    p2->next = p1;
    p1->next = p3; break;
    }
    else
    {
    p2 = p2->next;
    }
    }
    if (p2->next == NULL)
    {
    p2->next = p1;
    p1->next = NULL;
    }
    }
    }
    } return head;
    }