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. 多帧图片转gif

    示例 工具photosh cc2017 1: 文件--> 脚本--> 将文件载入堆栈--> 选择文件-->勾选窗口的时间轴-->底部 从图层建立帧--> 设置时间延 ...

  2. Android自定义日历控件(继承系统控件实现)

    Android自定义日历控件(继承系统控件实现) 主要步骤 编写布局 继承LinearLayout设置子控件 设置数据 继承TextView实现有圆圈背景的TextView 添加Attribute 添 ...

  3. js判断PC端与移动端跳转

    在网上看到很多这样类似的代码,但是有的很复杂,或者有的没有判断完全,上次经理去见完客户回来讲,使用苹果浏览打开pc端(pc已经做了识别跳转)会自动跳转到移动端的网页去,后来经测试才发现 documen ...

  4. Kattis - ACM Contest Scoring

    ACM Contest Scoring Our new contest submission system keeps a chronological log of all submissions m ...

  5. udev的规则文件

    转载于:https://linux.cn/article-9365-1.html 介绍 在 GNU/Linux 系统中,虽然设备的底层支持是在内核层面处理的,但是,它们相关的事件管理是在用户空间中通过 ...

  6. BZOJ 1834: [ZJOI2010]network 网络扩容 最小费用流_最大流_残量网络

    对于第一问,跑一遍最大流即可. 对于第二问,在残量网络上的两点间建立边 <u,v>,容量为无限大,费用为扩充费用. 跑一遍最小费用流即可. Code: #include <vecto ...

  7. anshi

    env.js主要是帮助我们读取根目录下以.env开头的环境变量,并判断是否生效. 比如在根目录下创建一个.env.local文件 改写一个环境变量 而没有改之前,它是在3000端口打开 path.js ...

  8. 洛谷 P1147 连续自然数和 (滑动窗口)

    维护一个滑动窗口即可 注意不能有m到m的区间,因为区间长度要大于1 #include<cstdio> #define _for(i, a, b) for(int i = (a); i &l ...

  9. vue懒加载

    vue懒加载(白屏或者加载慢的解决方法) 懒加载:也叫延迟加载,即在需要的时候进行加载,随用随载. 为什么需要懒加载? 像vue这种单页面应用,如果没有应用懒加载,运用webpack打包后的文件将会异 ...

  10. 洛谷 2921 记忆化搜索 tarjan 基环外向树

    洛谷 2921 记忆化搜索 tarjan 传送门 (https://www.luogu.org/problem/show?pid=2921) 做这题的经历有点玄学,,起因是某个random题的同学突然 ...