首页 > 代码库 > 链表实现与遍历
链表实现与遍历
#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;
}
链表实现与遍历
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。