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=…
http://www.geeksforgeeks.org/flattening-a-linked-list/ #include <iostream> #include <vector> #include <algorithm> #include <queue> #include <stack> #include <string> #include <fstream> #include <map> #includ…
http://www.geeksforgeeks.org/detect-and-remove-loop-in-a-linked-list/ #include <iostream> #include <vector> #include <algorithm> #include <queue> #include <stack> #include <string> #include <fstream> #include <…
http://www.geeksforgeeks.org/reverse-a-list-in-groups-of-given-size/ #include <iostream> #include <vector> #include <algorithm> #include <queue> #include <stack> #include <string> #include <fstream> #include <m…
http://www.geeksforgeeks.org/merge-sort-for-linked-list/ #include <iostream> #include <vector> #include <algorithm> #include <queue> #include <stack> #include <string> #include <fstream> #include <map> #incl…
http://www.geeksforgeeks.org/write-a-function-to-get-the-intersection-point-of-two-linked-lists/ 第一第二个方法比较简单,下面这段代码是第三个方法 #include <iostream> #include <vector> #include <algorithm> #include <queue> #include <stack> #include &…
http://www.geeksforgeeks.org/function-to-check-if-a-singly-linked-list-is-palindrome/ 这里的reverse可以reverse整个list,这样空间需求就是O(n),不如这个网页写的O(1)的方法 #include <iostream> #include <vector> #include <algorithm> #include <queue> #include <s…
iterative太简单不写了 http://www.geeksforgeeks.org/write-a-function-to-reverse-the-nodes-of-a-linked-list/ #include <iostream> #include <vector> #include <algorithm> #include <queue> #include <stack> #include <string> #includ…
Stack & Queue Implementations FixedCapacityQueue package cn.edu.tsinghua.stat.mid_term; import java.util.Objects; /** * Created by shuaiyi on 04/11/2017. */ public class FixedCapacityQueue<T> { private int size; private int head; private int tai…
We can realize a Stack as an adaptation of a Python List. S.push(e)=L.append(e) S.pop()=L.pop() S.top()=L[-1] S.len()=len(L) S.is_empty=(len(L)==0) class Empty(Exception): pass class ArrayStack: """LIFO Stack implementation using Python&quo…