码迷,mamicode.com
首页 > 其他好文 > 详细

链表实现与遍历

时间:2014-09-24 23:50:07      阅读:277      评论:0      收藏:0      [点我收藏+]

标签:io   sp   c   amp   ef   r   bs   type   as   

#include <stdio.h>//单向循环链表实现与遍历

typedef struct Node {

int data;

 

struct Node *next;

} Node;

int main ()

{

Node n1 = {1, NULL};

Node n2 = {2, NULL};

Node n3 = {3, NULL};

Node n4 = {4, NULL};

 

n1.next = &n2;

n2.next = &n3;

n3.next = &n4;

n4.next = &n1;

 

Node *pn = &n1;

 

do {

printf("%d\n", pn->data);

pn = pn->next;

} while(pn != &n1);

 

return 0;

 

 

#include <stdio.h>//单向链表实现与遍历

typedef struct Node {

int data;

 

struct Node *next;

} Node;

int main ()

{

Node n1 = {1, NULL};

Node n2 = {2, NULL};

Node n3 = {3, NULL};

Node n4 = {4, NULL};

 

n1.next = &n2;

n2.next = &n3;

n3.next = &n4;

 

Node *pn = &n1;

 

while(pn!=NULL)

{

  printf("%d",pn->data);

  pn=pn->next;

}

 

return 0;

链表实现与遍历

标签:io   sp   c   amp   ef   r   bs   type   as   

原文地址:http://www.cnblogs.com/a514875560/p/3991579.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!