交换单链表中相邻的两个点(人搜)
来源:互联网 发布:fps画面优化 编辑:程序博客网 时间:2024/05/14 20:17
/************************************************************* * file:reverse_twins_node_of_list.c * brief:交换单链表中相邻的两个点 * yejing@2015.1.20 1.0 creat *************************************************************/#include <stdio.h>#include <stdlib.h>typedef struct _node_t{struct _node_t *next;int value;}node_t;node_t* creat_list(int n){if(!n) return NULL;int i = 1;node_t* phead = (node_t*)malloc(sizeof(node_t));phead->next = NULL;phead->value = 1;if(!phead)return NULL;node_t *p, *q;p = q = phead;for(i = 1; i < n; ++i){q = (node_t*)malloc(sizeof(node_t));p->next = q;p = q;p->value = i + 1;}return phead;}node_t* reverse_twins_node_of_list(node_t* phead){if(!phead)return NULL;if(!phead->next)return phead;int i = 2;node_t* n = phead;phead = phead->next->next;while(i){node_t* m = n;n = n->next;m->next = phead;phead = m;--i;}phead->next->next = reverse_twins_node_of_list(phead->next->next);return phead;}void show_list(node_t* phead, int before_after){if(!phead)return;node_t* tmp = phead;if(before_after)printf("before transfer ");elseprintf("after transfer ");printf("list is:");while(tmp){printf(" %d", tmp->value);tmp = tmp->next;}printf("\n");return;}int main(int argc, char* argv[]){int count;printf("input list node count:\n");scanf("%d", &count);getchar();node_t* phead = creat_list(count);show_list(phead, 1);phead = reverse_twins_node_of_list(phead);show_list(phead, 0);return 1;}执行结果:
0 0
- 交换单链表中相邻的两个点(人搜)
- 交换单链表中相邻的两个元素 Swap Nodes in Pairs
- leetcode交换相邻的两个节点的值
- 8.通过调整链来交换两个相邻的元素
- (LeetCode)Swap Nodes in Pairs --- 交换两个相邻的结点
- 只调整指针来交换两个相邻的元素【单链表】
- 只调整指针来交换两个相邻的元素【双链表】
- 单链表相邻两个节点之间交换顺序
- 通过只调整指针(而不是数据)来交换两个相邻的元素
- Swap Nodes in Pairs(交换链表相邻的两个结点)
- 练习 3.3 通过只调整指针(不是数据)来交换两个相邻的元素
- 单向链表 练习3.3 通过只调整指针来交换两个相邻的元素
- 判断邻接矩阵中两个点是否相邻
- 相邻交换
- C/C++之 交换字符串中相邻两个字节
- 交换单向链表的相邻节点
- 交换链表中相邻节点的位置
- p62 练习3.3 通过只调整指针(而不是数据)来交换两个相邻的元素,使用:
- 正则的贪婪与非贪婪模式
- ADB架构
- 2014年国内智能家居市场发展报告(完整版)
- shell脚本笔记(二)Condition Evaluation Utility
- jquery最常用的几个函数
- 交换单链表中相邻的两个点(人搜)
- online_judge_1489
- 401 - Palindromes
- Hierarchy-Viewer架构
- (cocs2dx)二、 利用Eclipse编译apk应用
- 基于Qt5的俄罗斯方块的开发学习(1)
- android环境离线搭建
- 黑马程序员-⑦内存管理
- (精)构建高并发高可用的电商平台架构实践