|
发表于 2019-9-23 22:11:44
|
显示全部楼层
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- typedef struct student
- {
- int data ;
- struct student * next ;
- } Node ;
- Node * CreateList(Node * L , int n)
- {
- Node * h , * p , * q ;
- h = p = L ;
- q = (Node *) malloc(sizeof(Node)) ;
- q -> data = n ;
- q -> next = NULL ;
- if(p) {
- while(p -> next) p = p -> next ;
- p -> next = q ;
- } else {
- h = q ;
- }
- return h ;
- }
- void See(Node * L)
- {
- Node * p ;
- if(p) {
- while(p) {
- printf("%d\n" , p -> data) ;
- p = p -> next ;
- }
- } else {
- printf("链表为空!\n") ;
- }
- }
- int main()
- {
- Node * L ;
- L = CreateList(NULL , 20) ;
- CreateList(L , 10) ;
- CreateList(L , 5) ;
- CreateList(L , 35) ;
- CreateList(L , 45) ;
- See(L) ;
- }
复制代码 |
|