单链表倒序
来源:互联网 发布:北京seo教程 编辑:程序博客网 时间:2024/06/05 10:42
需要将单链表倒序,并输出新的链表
核心代码
- Node *next = root->next;
- root->next = new_root;
- new_root = root;
- root = next;
#include <stdio.h>typedef struct Node { char data; struct Node* next;} Node;void print_list(Node* root) { while (root) { printf("%c ", root->data); root = root->next; } printf("\n");}Node* reverse(Node* root) { Node* new_root = NULL; while (root) { Node* next = root->next; root->next = new_root; new_root = root; root = next; } return new_root;}int main() { Node f = { 'f', NULL }; Node e = { 'e', &f }; Node d = { 'd', &e }; Node c = { 'c', &d }; Node b = { 'b', &c }; Node a = { 'a', &b }; Node* root = &a; print_list(root); root = reverse(root); print_list(root); return 0;}
0 0
- 倒序单链表
- 单链表倒序
- 单链表倒序
- 单链表倒序
- 单链表倒序
- 单链表倒序
- 单链表的倒序
- 单链表倒序算法
- 单链表倒序输出
- 单链表的倒序
- 倒序打印一个单链表
- 倒序输出单链表
- 单链表反转与倒序
- 倒序打印单链表
- 倒序
- 倒序输出单链表的内容
- js创建单链表及倒序单链表
- 借用栈实现单链表逆向倒序输出
- Android学习笔记(2)--滚动视图
- perl中pack函数的用法
- jquery-取消冒泡
- java 调用webservice的各种方法总结
- Hibernate关系映射总结(转载)
- 单链表倒序
- 数据挖掘学习
- 关于Ubuntu12.04重启后无法进入图形界面的解决方法
- Spring 注解--@RequestMapping
- UILabel 换行
- 配置Spket和Extjs的提示路径在Myeclipse中
- jquery常用事件及特效
- 通过#pragma pack(n)改变C编译器的字节对齐方式
- 一些好博客链接(持续更新)