[Data Structure] Linked List Implementation in Python
class Empty(Exception):
pass class Linklist: class _Node:
# Nonpublic class for storing a linked node
__slots__='_element','_next' def __init__(self,ele,ne):
self._element=ele
self._next=ne def __init__(self):
self._head=None
self._size=0
self._tail=None def __len__(self):
return self._size def is_empty(self):
return self._size==0 def add_first(self,e):
self._head=self._Node(e,self._head)
if self._size==0:
self._tail=self._head
self._size+=1 def add_last(self,e):
newlastnode=self._Node(e,None)
if ~self.is_empty():
self._tail._next=newlastnode
self._tail=newlastnode
else:
self._tail=newlastnode
self._size+=1 def remove_first(self):
if self.is_empty():
raise Empty("The linked is empty")
self._head=self._head._next
self._size-=1
[Data Structure] Linked List Implementation in Python的更多相关文章
- Data Structure Linked List: Flattening a Linked List
http://www.geeksforgeeks.org/flattening-a-linked-list/ #include <iostream> #include <vector ...
- Data Structure Linked List: Detect and Remove Loop in a Linked List
http://www.geeksforgeeks.org/detect-and-remove-loop-in-a-linked-list/ #include <iostream> #inc ...
- Data Structure Linked List: Reverse a Linked List in groups of given size
http://www.geeksforgeeks.org/reverse-a-list-in-groups-of-given-size/ #include <iostream> #incl ...
- Data Structure Linked List: Merge Sort for Linked Lists
http://www.geeksforgeeks.org/merge-sort-for-linked-list/ #include <iostream> #include <vect ...
- Data Structure Linked List: Write a function to get the intersection point of two Linked Lists.
http://www.geeksforgeeks.org/write-a-function-to-get-the-intersection-point-of-two-linked-lists/ 第一第 ...
- Data Structure Linked List: Function to check if a singly linked list is palindrome
http://www.geeksforgeeks.org/function-to-check-if-a-singly-linked-list-is-palindrome/ 这里的reverse可以re ...
- Data Structure Linked List: Write a function to reverse a linked list
iterative太简单不写了 http://www.geeksforgeeks.org/write-a-function-to-reverse-the-nodes-of-a-linked-list/ ...
- Data structure basics - Java Implementation
Stack & Queue Implementations FixedCapacityQueue package cn.edu.tsinghua.stat.mid_term; import j ...
- [Data Structure] Stack Implementation in Python
We can realize a Stack as an adaptation of a Python List. S.push(e)=L.append(e) S.pop()=L.pop() S.to ...
随机推荐
- 使用cocos创建的项目,如何进行源码调试?
环境cocos3.10,里面包含了cocos2dx 3.10引擎.但是用cocos创建出来的项目,使用的lib和dll是文件夹Cocos\Cocos2d-x\cocos2d-x-3.10\prebui ...
- 雷林鹏分享:Ruby 数据类型
Ruby 数据类型 本章节我们将为大家介绍 Ruby 的基本数据类型. Ruby支持的数据类型包括基本的Number.String.Ranges.Symbols,以及true.false和nil这几个 ...
- 使用 Python 的 Socket 模块构建一个 UDP 扫描工具
译文:oschina 英文:bt3gl 当涉及到对一些目标网络的侦察时,出发点无疑是首先发现宿主主机.这个任务还可能包含嗅探和解析网络中数据包的能力. 几周前,我曾经谈到了如何使用Wireshark来 ...
- LeetCode--108--将有序数组转化为二叉搜索树
问题描述: 将一个按照升序排列的有序数组,转换为一棵高度平衡二叉搜索树. 本题中,一个高度平衡二叉树是指一个二叉树每个节点 的左右两个子树的高度差的绝对值不超过 1. 示例: 给定有序数组: [-10 ...
- 1 python基础知识
一.python简介 编译型:将所有的源码先编译成机器型语言,并保存为二进制文件,然后一次性执行c c++ go swift 解释型:将代码一行一行边编译边解释python javascript ph ...
- Mysql查询用逗号分隔的字段-字符串函数FIND_IN_SET(),以及此函数与in()函数的区别
查询用逗号分隔的字段,可以用字符串函数FIND_IN_SET(): 查询数据库表中某个字段(值分行显示),可以用函数in(). 今天工作中遇到一个问题,就是用FIND_IN_SET()函数解决的. 第 ...
- Sql server函数的学习2(游标函数、日期函数、字符串操纵函数)
一.游标函数与变量 游标可以处理多行数据,在过程循环中一次访问一行.和基于集合的高效操作相比,这个功能对系统资源的消耗更大. 可以用一个函数和两个全局变量来管理游标操作 1.CURSOR_STATUS ...
- sql 判断字符串中是否含有数字和字母
判断是否含有字母 select PATINDEX('%[A-Za-z]%', ‘ads23432’)=0 (如果存在字母,结果<>1) 判断是否含有数字 PATINDEX('%[0-9]% ...
- 快速切题sgu126. Boxes
126. Boxes time limit per test: 0.25 sec. memory limit per test: 4096 KB There are two boxes. There ...
- 什么是REST API?
REST指一组架构约束条件和原则,满足约束条件和原则的应用程序设计.架构,软件体系结构分为三部分:构建,用于描述计算机:连接器,用于描述构建的链接部分:配置将构建和连接器组成有机整体.web基本技术: ...