首页 | 博客群 | 公社 | 专栏 | 论坛 | 图片 | 资讯 | 注册 | 帮助 | 博客联播 | 随机访问
ASCII码文件的存储与输出- -| 回首页 | 2005年索引 | - -两个矩阵相乘

创建一个链表

                                      

编写一个CREATE()函数,按照规定的接点结构,创建一个单链表。

#define   NULL  0

#define   LEN     sizeof(struct grade)
struct  grade
   { char  no[7];    
      int  score;    
      struct  grade  *next;   
    };
struct grade *create( void )
    { struct grade *head=NULL, *new, *tail;
        int count=0;               
        for(  ;   ;  )                
        { new=(struct grade *)malloc(LEN); 

printf("Input the number of student No.%d(6 bytes): ", count+1);
scanf("%6s", new->no);
if(strcmp(new->no,"000000")==0)   
      { free(new);                      
         break;                                   }
printf("Input the score of the student No.%d: ", count+1);
scanf("%d", &new->score);
count++;                       
new->next=NULL;

if(count==1)  head=new; 
      else  tail->next=new;      
       tail=new;                        
     }
   return(head);
}      

#define   NULL  0

#define   LEN     sizeof(struct grade)
struct  grade
   { char  no[7];    
      int  score;    
      struct  grade  *next;   
    };
struct grade *create( void )
    { struct grade *head=NULL, *new, *tail;
        int count=0;               
        for(  ;   ;  )                
        { new=(struct grade *)malloc(LEN); 

printf("Input the number of student No.%d(6 bytes): ", count+1);
scanf("%6s", new->no);
if(strcmp(new->no,"000000")==0)   
      { free(new);                      
         break;                                   }
printf("Input the score of the student No.%d: ", count+1);
scanf("%d", &new->score);
count++;                       
new->next=NULL;

if(count==1)  head=new; 
      else  tail->next=new;      
       tail=new;                        
     }
   return(head);
}      

main()

struct gride *head;
    head=create();
}

【作者: 刘加开】【访问统计:】【2005年04月15日 星期五 22:23】【注册】【打印

Trackback

你可以使用这个链接引用该篇文章 http://publishblog.blogchina.com/blog/tb.b?diaryID=1207456

回复

- 评论人:ww   2007-01-17 17:35:10   

new 是c语言里的常用字啊,编译回出错的.不过改为其他字就没事了

验证码:   
评论内容: