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的更多相关文章

  1. Data Structure Linked List: Flattening a Linked List

    http://www.geeksforgeeks.org/flattening-a-linked-list/ #include <iostream> #include <vector ...

  2. 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 ...

  3. 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 ...

  4. Data Structure Linked List: Merge Sort for Linked Lists

    http://www.geeksforgeeks.org/merge-sort-for-linked-list/ #include <iostream> #include <vect ...

  5. 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/ 第一第 ...

  6. 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 ...

  7. 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/ ...

  8. Data structure basics - Java Implementation

    Stack & Queue Implementations FixedCapacityQueue package cn.edu.tsinghua.stat.mid_term; import j ...

  9. [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 ...

随机推荐

  1. Unix网络编程_卷1卷2

    1. UNIX 网络编程(第2版)第1卷:套接口API和X/Open 传输接口API PDFhttp://www.linuxidc.com/Linux/2014-04/100155.htm UNIX网 ...

  2. Jedis 之 初始<一>

    package xx.jedis; import java.util.Set; import redis.clients.jedis.Jedis; import redis.clients.jedis ...

  3. LeetCode--171--Excel表列序号

    问题描述: 给定一个Excel表格中的列名称,返回其相应的列序号. 例如, A -> 1 B -> 2 C -> 3 ... Z -> 26 AA -> 27 AB -& ...

  4. 2-18,19 搭建MySQL主从服务器并并通过mysql-proxy实现读写分离

    MySQL主从服务器 实现方式: MySQL  REPLICATION Replication可以实现将数据从一台数据库服务器(master)复制到一台或多台数据库服务器(slave) 默认情况下这种 ...

  5. C#窗体控件简介ListBox

    ListBox 控件 ListBox 控件又称列表框,它显示一个项目列表供用户选择.在列表框中,用户 一次可以选择一项,也可以选择多项. 1.常用属性: (1) Items属性: 用于存放列表框中的列 ...

  6. PL/SQL Developer 一段时间后变慢,且导致数据库CPU100%的问题(转)

    参考: 一段时间不用plsql developer之后重新使用会变得很慢 plsql developer连接数据库导致服务器cpu升高的案例 1.pl/sql dev 变慢的问题,建议设置如下 2. ...

  7. 巧妙利用SVN 实现复制需要部署的文件。

    http://blog.csdn.net/xiaoding133/article/details/39252357 http://blog.csdn.net/sinat_29173167/articl ...

  8. 学习浏览器缓存(http缓存)

    Q: 浏览器缓存是个什么东东,为什么要学习浏览器缓存涅? A: 浏览器缓存其实就是浏览器保存通过HTTP获取的所有资源,是浏览器将网络资源存储在本地的一种行为.浏览器缓存可以减少冗余数据的传输,减小服 ...

  9. jenkins邮件配置----jenkins笔记(三)

    转载地址:https://www.cnblogs.com/sylvia-liu/p/4527390.html 前言 最近搭建Maven+Testng+jenkins的持续集成环境,希望最后实现自动邮件 ...

  10. Hexo博客搭建教程

    1.使用淘宝npm源 $ npm install -g cnpm --registry=https://registry.npm.taobao.org 2.安装hexo cnpm install -g ...