链表- Java和C的实现

C语言中的链表实现

预先准备的知识:

  建立结构体类型:

struct 结构体名{
  成员列表  
}变量名列表;
变量名 *指针名; //结构体指针

  升级版建立结构体类型:

typedef struct{
  成员列表;      
}变量名列表;
变量名 *指针名; //结构体指针

C语言之静态链表:

 1 #include<stdio.h>
 2 struct Student
 3 {
 4     int num;
 5     float score;
 6     struct Student * next;  
 7 };
 8 int main()
 9 {
10     struct Student a,b,c,*head,*p;
11     a.num=10101;a.score=89.5;
12     b.num=10103;b.score=90;
13     c.num=10107;c.score=85;
14     head=&a;
15     a.next=&b;
16     b.next=&c;
17     c.next=&NULL;
18     p=head;
19     do
20     {
21        printf("%ld%.1f\n",p->num,p->score);
22        p=p->next;
23     }  while(p!=NULL);
24    return 0;
25 }

 

 

 java中链表的实现

posted @ 2022-03-21 16:14  Porker_ZHU  阅读(43)  评论(0)    收藏  举报