class Node(object):
def __init__(self):
self.val = None
self.next = None class Node_handle():
def __init__(self):
self.cur_node = None
  # 查找
def find(self,node,num,a = 0):
while node:
if a == num:
return node
a += 1
node = node.next
  # 增加
def add(self,data):
node = Node()
node.val = data
node.next = self.cur_node
self.cur_node = node
return node
  # 打印
def printNode(self,node):
while node:
print ('\nnode: ', node, ' value: ', node.val, ' next: ', node.next)
node = node.next
  # 删除
def delete(self,node,num,b = 1):
if num == 0:
node = node.next
return node
while node and node.next:
if num == b:
node.next = node.next.next
b += 1
node = node.next
return node
  # 翻转
def reverse(self,nodelist):
list = []
while nodelist:
list.append(nodelist.val)
nodelist = nodelist.next
result = Node()
result_handle =Node_handle()
for i in list:
result = result_handle.add(i)
return result if __name__ == "__main__":
l1 = Node()
ListNode_1 = Node_handle()
l1_list = [1, 8, 3]
for i in l1_list:
l1 = ListNode_1.add(i)
ListNode_1.printNode(l1)
l1 = ListNode_1.delete(l1,0)
ListNode_1.printNode(l1)
l1 = ListNode_1.reverse(l1)
ListNode_1.printNode(l1)
l1 = ListNode_1.find(l1,1)
ListNode_1.printNode(l1)

ListNode的python 实现的更多相关文章

  1. 从尾到头打印链表(python)

    题目描述 输入一个链表,按链表值从尾到头的顺序返回一个ArrayList. # -*- coding:utf-8 -*- # class ListNode: # def __init__(self, ...

  2. Linux下编译安装源码包软件 configure ,make, make install, make test/check, make clean

    http://www.360doc7.net/wxarticlenew/541275971.html 一.什么是源码包软件? 顾名思义,源码包就是源代码的可见的软件包,基于Linux和BSD系统的软件 ...

  3. Linux下编译安装源码包软件 configure ,make, make install, make test/check, make clean 假目标

    http://www.360doc7.net/wxarticlenew/541275971.html 一.程序的组成部分 Linux下程序大都是由以下几部分组成: 二进制文件:也就是可以运行的程序文件 ...

  4. python leetcode 1

    开始刷 leetcode, 简单笔记下自己的答案, 目标十一结束之前搞定所有题目. 提高一个要求, 所有的答案执行效率必须要超过 90% 的 python 答题者. 1. Two Sum. class ...

  5. 21. Merge Two Sorted Lists —— Python

    题目: Merge two sorted linked lists and return it as a new list. The new list should be made by splici ...

  6. 使用Python和Perl绘制北京跑步地图

    当你在一个城市,穿越大街小巷,跑步跑了几千公里之后,一个显而易见的想法是,如果能把在这个城市的所有路线全部画出来,会是怎样的景象呢? 文章代码比较多,为了不吊人胃口,先看看最终效果,上到北七家,下到南 ...

  7. python面试2

    Python语言特性 1 Python的函数参数传递 看两个例子:     1 2 3 4 5 a = 1 def fun(a):     a = 2 fun(a) print a  # 1 1 2 ...

  8. [LeetCode]题解(python):092 Reverse Linked List II

    题目来源 https://leetcode.com/problems/reverse-linked-list-ii/ Reverse a linked list from position m to  ...

  9. [LeetCode]题解(python):086 - Partition List

    题目来源 https://leetcode.com/problems/partition-list/ Given a linked list and a value x, partition it s ...

随机推荐

  1. 自定义view 之多个引导层动画效果

    SupernatantView 如果我英文还可以的话这个应该叫做漂浮在上层的view---引导层 今天闲来无事看了网上的一些引导层案例总感觉如果不是很舒服,就是类似于很死板的显示和消失 我在想能不能弄 ...

  2. golden gate的DDL配置

    DDL复制的配置 目前只支持oracle和teradata的ddl复制 oracle能复制除了系统对象之外的所有对象 两种配置方法: 基于trigger的DDL:对于生产库有一定影响. 原理: 源库建 ...

  3. windows 2008 中IIS7.0以上如何设置404错误页面

    404错误页面的设置,不仅仅可以提高用户体验度,从SEO方面考虑,也是非常重要的.今天,笔者在这里介绍一下在windows 2008下如何设置404错误页面. 注意:设置404有我这里介绍2种方式,推 ...

  4. 手机号获取省份,城市api的使用

    function get_mobile_area($mobile){ header('Content-Type:text/html;charset=gbk'); $url = 'http://life ...

  5. Oracle的分页查询及内联视图和函数处理

    1.Oracle的分页常用方式: select * from(select * ,ROWNUM num from table where ROWNUM<=20 ) where num>0; ...

  6. 路飞学城Python-Day36

    24-记录的增删改查 1. 插入完整数据(顺序插入) 语法一: INSERT INTO 表名(字段1,字段2,字段3…字段n) VALUES(值1,值2,值3…值n);   语法二: INSERT I ...

  7. 使用python备份数据库并删除备份超过一定时长的文件

    #!/usr/bin/env python #-*- coding: utf-8 -*- """ @Project:Py @author:sandu @Email: sa ...

  8. [terry笔记]Oracle SQL 优化之sql tuning advisor (STA)

    前言:经常可以碰到优化sql的需求,开发人员直接扔过来一个SQL让DBA优化,然后怎么办? 当然,经验丰富的DBA可以从各种方向下手,有时通过建立正确索引即可获得很好的优化效果,但是那些复杂SQL错综 ...

  9. 2015 Multi-University Training Contest 5 hdu 5348 MZL's endless loop

    MZL's endless loop Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Oth ...

  10. angular-Scope

    Scope(作用域) 是应用在 HTML (视图) 和 JavaScript (控制器)之间的纽带. Scope 是一个对象,有可用的方法和属性. Scope 可应用在视图和控制器上. 当你在 Ang ...