1. 程式人生 > >c 最簡單的鏈表

c 最簡單的鏈表

node tab while main cnblogs 變量 簡單的 clu str

#include <stdio.h>

struct node
{
int data;
struct node *next; //指向本身的指針
};
//
main()
{
struct node a,b,c,*h,*p;//定義結構體和結構體指針
a.data=10;    //設置結構體變量的值
b.data=20;
c.data=30;
h=&a;         //設置結構體指針的指向
a.next=&b;
b.next=&c;
c.next=\0;
p=h;          //賦值,用於打印
while(p)
{
printf("-->%d",p->data);    //打印,然後指向下一個
p
=p->next; printf("\n"); } /* vim: set ft=cpp expandtab ts=4 sw=4 sts=4 tw=100: */ }

c 最簡單的鏈表