首页 > 其他 > 详细

链表实现与遍历

时间:2014-09-24 22:57:58      阅读:318      评论:0      收藏: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;

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;

链表实现与遍历

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!