Python 实现列表 偶数位与奇数反转
2017-06-14 20:32
531 查看
1->2->3->4转换成
2->1->4->3class ListNode:def __init__(self, x):self.val = xself.next = Noneclass Sort:def swapList(self,head):if head is not None and head.next is not None:next = head.nexthead.next = self.swapList(next.next)next.next = headreturn nextreturn headl1 =ListNode(1)l2 =ListNode(2)l3 =ListNode(3)l4 =ListNode(4)l1.next = l2l2.next = l3l3.next = l4sor = Sort()l5 = sor.swapList(l1)while l5 is not None:print(l5.val)l5 =l5.next
相关文章推荐
- 调整数组顺序使奇数位于偶数前面[剑指offer]之python实现
- Python偶数奇数简单实现
- 用python实现的可以拷贝或剪切一个文件列表中的所有文件
- 用访问列表过滤奇数和偶数ip地址
- Java用三元运算符判断奇数和偶数的简单实现
- php实现数组筛选奇数和偶数示例
- 假设一个数组A[n]数据均为整形,设计一个O(n)的算法,实现将所有奇数放在数组左侧,所有偶数放在右侧
- CSS实现IE下奇数行与偶数行、奇数列与偶数列背景颜色的变换
- Python中无限元素列表的实现方法
- [Python]实现字符串反转的三个方法
- 算法实现数组前半部分为奇数,后半部分为偶数。
- 单链表反转python实现
- Python中利用列表推导式实现矩阵置换时发现的"问题"
- 去掉python列表中的偶数
- 求一段CSS样式代码;要求是Table的标签样式,实现Table标签奇数行显示一个颜色;偶数行显示另外一种颜色
- python 数据结构之顺序列表的实现
- 实现将线性表奇数和偶数分开。
- 算法实现数组前半部分为奇数,后半部分为偶数。
- 调整数组顺序实现:奇数在偶数前面 以及 “奇偶奇偶”相间
- python数据结构与算法 18 无序列表的实现