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. 关于获取WebForm控件的问题

    遇到这样的一个问题: 在GridView加载了数据之后,GridView的个别列被设置为TextBox单元格,就是可以修改数量了,单价什么的: 这样就触发了TextChanged事件: 现在要记录谁修 ...

  2. CheckBox的Attributes

    在看老同事写的代码的时候,发现了这样的一段代码:之前自己没有遇到过,记录下吧. 大致是这样的 foreach (GridViewRow grv in GridView1.Rows) { CheckBo ...

  3. php语法学习:轻松看懂PHP语言

    基础语法 开头结尾 PHP脚本以 "<?php " 开头以 "?>" 结尾 <!DOCTYPE html> <html>&l ...

  4. JDBC程序实例

    实例 ( Statement ): public class JDBC { public static void main(String[] args) throws Exception { Conn ...

  5. 10、Latent Relational Metric Learning via Memory-based Attention for Collaborative Ranking-----基于记忆注意的潜在关系度量协同排序

    一.摘要: 本文模型 LRML(潜在相关度量学习)是一种新的度量学习方法的推荐.[旨在学习用户和项目之间的相关关系,而不是简单的用户和项目之间的push和pull关系,push和pull主要针对LMN ...

  6. css font-family 字体组

    介绍图片来自: http://www.runoob.com/cssref/css-websafe-fonts.html

  7. 移动设备safari不支持jquery的live绑定的解决方案

    给元素加上样式如下即可 <style> .btn{ cursor: pointer; } </style>

  8. 安装NexT主题

    Hexo 安装主题的方式非常简单,只需要将主题文件拷贝至站点目录的 themes 目录下, 然后修改下配置文件即可. 下载主题包 在终端窗口下,定位到 Hexo 站点目录下.使用 Git checko ...

  9. LaTeX 图片色偏解决方法

    本系列文章由 @YhL_Leo 出品,转载请注明出处. 文章链接: http://blog.csdn.net/yhl_leo/article/details/50327113 在LaTeX的编辑模式中 ...

  10. Reentrant protected mode kernel using virtual 8086 mode interrupt service routines

    A method for allowing a protected mode kernel to service, in virtual 8086 mode, hardware interrupts ...