单向链表的操作
来源:互联网 发布:银联数据2016校园招聘 编辑:程序博客网 时间:2024/05/21 22:21
#include "stdio.h"
#include "malloc.h"
struct Node* current = NULL; //声明的一个全局变量表示的是链表的尾部
struct Node
{
int value;
struct Node* next; //下一个节点
};
void addNode(struct Node *node) //添加一个节点
{
current->next = node;
current = current->next;
}
void readNode(struct Node *first) //遍历链表
{
struct Node* temp = first;
while(temp != NULL)
{
printf("%d\n", temp->value);
temp = temp->next;
}
}
int main()
{
struct Node* first = (struct Node*)malloc(sizeof(struct Node));
first->value = 1;
first->next = NULL;
current = first;
struct Node* node = (struct Node*)malloc(sizeof(struct Node));
node->value = 2;
node->next = NULL;
addNode(node);
node = (struct Node*)malloc(sizeof(struct Node));
node->value = 3;
node->next = NULL;
addNode(node);
node = (struct Node*)malloc(sizeof(struct Node));
node->value = 4;
node->next = NULL;
addNode(node);
readNode(first);
getchar();
return 0;
}
#include "malloc.h"
struct Node* current = NULL; //声明的一个全局变量表示的是链表的尾部
struct Node
{
int value;
struct Node* next; //下一个节点
};
void addNode(struct Node *node) //添加一个节点
{
current->next = node;
current = current->next;
}
void readNode(struct Node *first) //遍历链表
{
struct Node* temp = first;
while(temp != NULL)
{
printf("%d\n", temp->value);
temp = temp->next;
}
}
int main()
{
struct Node* first = (struct Node*)malloc(sizeof(struct Node));
first->value = 1;
first->next = NULL;
current = first;
struct Node* node = (struct Node*)malloc(sizeof(struct Node));
node->value = 2;
node->next = NULL;
addNode(node);
node = (struct Node*)malloc(sizeof(struct Node));
node->value = 3;
node->next = NULL;
addNode(node);
node = (struct Node*)malloc(sizeof(struct Node));
node->value = 4;
node->next = NULL;
addNode(node);
readNode(first);
getchar();
return 0;
}
- 单向链表的操作
- 单向链表的操作
- 单向链表的操作
- 单向链表的操作
- 单向链表的操作
- 单向链表的操作
- 单向链表的操作
- 单向链表的操作
- 单向链表,单向循环链表的基本操作
- java对单向单向链表的操作
- 单向链表操作
- 单向链表操作
- 单向链表操作
- 有序单向链表的相关操作
- java 单向链表的操作
- 基本单向链表的操作
- 单向链表的基本操作
- 单向链表的一些操作
- C# 生成随机数
- CREATE TABLESPACE命令详解
- YUV 简单转换程序
- Oracle Data Guard 环境下的数据库升级方法
- 2011年职业发展规划_无线PM
- 单向链表的操作
- Apache MINA NIO模型
- Android 常用代码集合
- 将excel 2007中的数据复制为图片
- ORA-16401 archivelog rejected by RFS 解决方法
- 【线程同步学习笔记】C#中的lock关键字
- WIN32_FIND_DATA
- php使用iconv进行从utf-8转为gb2312字符编码出错解决方案
- 面试题:链表插入排序、冒泡排序