[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 ...
随机推荐
- iterator_教程中的讲解
ZC: 在讲 vector的时候讲到的 1.分类: (1).输入(只读) 只支持一遍算法 (2).输出(只写) 只支持一遍算法 (3).正向 可对一个值进行多次读写 ==> 相当于 输入迭代器+ ...
- js 转码思维
<body> <script type="text/javascript"> // var el = document.createElement('scr ...
- shuoj 418 丢史蒂芬妮(素数筛+sg函数)
丢史蒂芬妮 代码: #include<bits/stdc++.h> using namespace std; +; int SG[N][N]; bool S[N]; vector<i ...
- Nginx配置https, 80端口重定向443
server { listen 443 ssl; server_name 域名; charset utf-8; access_log /var/log/nginx/webhook.iminho.me/ ...
- BST(二叉排序树)的插入与删除
值得一说的是删除操作,删除操作我们分为三种情况: 1.要删的节点有两个孩子: 找到左子树中的最大值或者右子树中的最小值所对应的节点,记为node,并把node的值赋给要删除的节点del,然后删除nod ...
- POJ-2251 Dungeon Master (BFS模板题)
You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is composed of un ...
- 56. Merge Intervals 57. Insert Interval *HARD*
1. Merge Given a collection of intervals, merge all overlapping intervals. For example,Given [1,3],[ ...
- iOS UI-文本视图(UITextView)
#import "ViewController.h" @interface ViewController ()<UITextViewDelegate> @propert ...
- 获取Oracle数据库awr报告方法
--登录数据库 sqlplus username/passwd; --运行生成AWR报告脚本 SQL> @?/rdbms/admin/awrrpt.sql; --输入要生成报告的格式:htm ...
- Intel DAAL AI加速——神经网络
# file: neural_net_dense_batch.py #================================================================= ...