1. 程式人生 > >單向鏈表

單向鏈表

clas pan can name urn printf sca post alloc

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 struct node{
 4     int num;
 5     struct node *next;
 6 };
 7 int main(){
 8     struct node *p,*p1,*head;
 9         head=p=(struct node *)malloc(sizeof(struct node));
10             while(scanf("%d",&p->num)&&p->num!=0){
11 p1=p; 12 p=(struct node *)malloc(sizeof(struct node)); 13 p1->next=p; 14 } 15 p->next=NULL; 16 p=head; 17 printf("數據如下:\n"); 18 while(p->next!=NULL){ 19 printf("%d
",p->num); 20 p=p->next; 21 } 22 printf("\n"); 23 return 0; 24 }

單向鏈表