[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 ...
随机推荐
- Python mysql-表中数据的大量插入
2017-09-06 23:28:26 import pymysql db = pymysql.connect("localhost","root"," ...
- IntelliJ IDEA 阿里巴巴编码插件
良好的编码习惯的从这个IDEA插件开始 这是根据阿里巴JAVA开发规范.PDF 开发的代码提示插件 具体提示如下 这里可以扫描你项目下不规范的代码 如果侧插件CPU太卡的话也可以点击右边的 ...
- mate桌面xrdp无法登陆问题
vi /usr/libexec/xrdp/startwm.sh 或者/etc/xrdp/startwm.sh: 找到相应的发行版本,增加mate-session如下所示: # el if [ -r ...
- H5基础知识(一)
一.概述 HTML5 是html4.0 升级版 结构 Html5 .样式 css3 .行为: API 都有所增强 HTML5并不仅仅只是做为HTML标记语言的一个最新版本,更重要的是它制定了Web ...
- 『Numpy』常用方法记录
numpy教程 防止输出省略号 import numpy as np np.set_printoptions(threshold=np.inf) 广播机制 numpy计算函数返回默认是一维行向量: i ...
- ubuntu vim简单命令
1.ubuntu vim 一些基本的命令. :set nu 或着 set number 设置行数 :set nonu 取消行数 ctrl+u 将 ...
- 使用UTL_SMTP发送中文邮件及使用UTL_TCP从附件服务器获取中文附件
先上最重要的干货 发送邮件正文及主题的时候一定要使用convert重新编码 主题: utl_smtp.write_raw_data(l_mail_conn, utl_raw.cast_to_raw(c ...
- elment-ui table组件 -- 远程筛选排序
elment-ui table组件 -- 远程筛选排序 基于 elment-ui table组件 开发,主要请求后台实现筛选 排序的功能. 需求 排序 筛选 是对后台整个数据进行操作,而不是对当前页面 ...
- popen strtok 函数的使用
FILE * popen ( const char * command , const char * type ); int pclose ( FILE * stream ); type 参数只能 ...
- Java-Runtime 类
https://www.cnblogs.com/slyfox/p/7272048.html Java-Runtime 类 Runtime 类代表着Java程序的运行时环境,每个Java程序都有一个Ru ...