Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

帮忙。。谢谢

Posted by 00330001 at 2005-09-23 14:25:02 on Problem 2591
设计一个链表,先把N 个 2x+1顺序存进去,再按大小插入3x+1,并把后面的节点释放。
打印最后一个节点的值。。。
为什么???
#include <stdlib.h>
#include <stdio.h>
typedef struct node* link;
  struct node{
            int item;
            link next;
  };
 main()
   {
    int i,n,x=0;
    int key=1;
    scanf("%d ", &n);
    link t=malloc(sizeof (node));
    link a;
    link last;
    t=a;
    for(i=1;i<=n;i++)
     { 
        list a->next=malloc(sizeof (node));
        a=a->next;
        a->item=2*x+1;
        x++;
      }
     a=t;
     for(i=1;i<=n;i++)
     {
       t->item=3*key+1;
       a=a->next;
       if(a->item<t->item)
        {
          t=a->next;
          a->next=t->next;
          last=t;
         while(last->next->next)
            last->next=last->next->next;
          free(last->next->next);
          }
        }
      while(a->next)
       a=a->next;
      printf("%d\n", a->item);
        
    }


Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator