双向链表

LRU hashMap(拉链) + 双向链表 java实现

有些话、适合烂在心里 提交于 2019-12-04 11:52:16
//基于 hash (拉链法) + 双向链表,LRUcache //若改为开放寻址,线性探测法能更好使用cpuCache public class LRU { private class Node { Node p; //访问序 priv Node n; //访问序 next Node hn; //hash 拉链 next Object key; Object val; public Node() { } public Node(Object key, Object val) { this.key = key; this.val = val; } @Override public String toString() { return "Node{" + "key=" + key + ", val=" + val + ", hn=" + (hn == null ? "n" : hn.key) + ", p=" + (p == null ? "n" : p.key) + ", n=" + (n == null ? "n" : n.key) + '}'; } } Node head; Node tail; Node[] tables; int capa = 4; int tabSize; //2的整数倍 int count; int countLimit = 8; float

双向链表(未完)

北战南征 提交于 2019-12-02 03:29:27
ifndef VLYFLIST_H_ define VLYFLIST_H_ namespace vlyflist { //带头尾节点的双向链表 template <typename T> class VlyfList { public: friend class Iterator; //双向节点 struct Node { Node(T& x) : data(x), prev(nullptr), next(nullptr) {} T data; Node* prev; Node* next; }; //迭代器 class Iteretor { public: Iteretor(Node* node = nullptr) : current(node) {} //前置++ Iteretor& operator++() { current = current->next; return *this; } //后置++ Iteretor& operator++(int) { Iteretor tmp = *this; ++* this; return tmp; } //前置-- Iteretor& operator--() { current = current->prev; return *this; } //后置-- Iteretor& operator--(int) {

二叉搜索树与双向链表

谁说我不能喝 提交于 2019-11-30 03:20:33
题目描述 输入一棵二叉搜索树,将该二叉搜索树转换成一个排序的双向链表。要求不能创建任何新的结点,只能调整树中结点指针的指向。 /////////////////////////////////////////////////////////////// 下午有点晕晕的,感觉不太好,改了改也算是过了, 中序遍历,一开始不知道如何判断是该返回root左边的还是右边的节点,所以加了一个flag判断一下, 如果flag=1,说明对于上一层节点,这是左子树,那么返回root最右边的节点, 如果flag=2,说明对于上一层,这是右子树,那么返回root最左边的节点, flag=0,说明到了根节点那里,返回最左边的节点就是链表最开始的节点了。 ****************************************************************************************** 后来我看了解答,发现好像返回谁都行,因为你返回以后,上一层的root节点接收你返回的节点,如果这是左子树返回的,那么找到最后就是要连接的节点了 如果是右子树返回的,那么找到最左边的那个,就是root后面要跟着的节点了。 //还有一些细节比如为空之类的就不提了 1 /** 2 public class TreeNode { 3 int val = 0; 4 TreeNode

C双向链表

无人久伴 提交于 2019-11-29 06:17:28
# include <stdio.h> typedef int ElemType ; typedef struct Node { ElemType data ; struct Node * next ; struct Node * prior ; } Node ; typedef struct DoubleList { int length ; Node header ; } DoubleList ; void InitList ( DoubleList * ) ; int ListEmpty ( DoubleList * ) ; int ListLength ( DoubleList * ) ; void ListInsert ( DoubleList * , int , ElemType ) ; void PrintList ( DoubleList * ) ; void PrintList_Reverse ( DoubleList * ) ; void CreateList ( DoubleList * , int ) ; void ListDelete ( DoubleList * , int , int * ) ; void GetElem ( DoubleList * , int , int * ) ; void ClearList ( DoubleList * ) ;

双向链表

不羁的心 提交于 2019-11-28 01:01:41
一种更复杂的链表是“双向链表”或“双面链表”。每个节点有两个链接:一个指向前一个节点,当此节点为第一个节点时,指向空值;而另一个指向下一个节点,当此节点为最后一个节点时,指向空值。 操作 is_empty() 链表是否为空 length() 链表长度 travel() 遍历链表 add(item) 链表头部添加 append(item) 链表尾部添加 insert(pos, item) 指定位置添加 remove(item) 删除节点 search(item) 查找节点是否存在 实现 class Node ( object ) : """双向链表节点""" def __init__ ( self , item ) : self . item = item self . next = None self . prev = None class DLinkList ( object ) : """双向链表""" def __init__ ( self ) : self . _head = None def is_empty ( self ) : """判断链表是否为空""" return self . _head == None def length ( self ) : """返回链表的长度""" cur = self . _head count = 0 while cur !=

C++双向链表

那年仲夏 提交于 2019-11-27 00:59:13
template<class T> class DLLNode { public: DLLNode() { next = prev = 0; } DLLNode(const T& el, DLLNode* n = 0, DLLNode * p = 0) { info = el; next = n; prev = p; } T info; DLLNode* next, * prev; }; template<class T> class DoublyLinkedList { public: DoublyLinkedList() { head = tail = 0; } void Add(const T&); T DeleteLast(); bool isEmpty() { return head == 0; } private: DLLNode<T>* head, * tail; }; template<class T> void DoublyLinkedList<T>::Add(const T& el) { if (tail != 0) { tail = new DLLNode<T>(el, 0, tail); tail->prev->next = tail; } else { head = tail = new DLLNode<T>(el); } } template<class

js算法练习--双向链表

帅比萌擦擦* 提交于 2019-11-26 12:07:41
class Node{ constructor(element){ this.element=element; this.pre=null; this.next=null; } } class DoubleLink{ constructor(){ this.head=null; this.tail=null; this.length=0; } Append(element) { var node=new Node(element); if(this.head==null) { this.head=node; this.tail=node; } else{ this.tail.next=node; node.pre=this.tail; this.tail=node; } this.length++; } Insert(element,position){ if(position<0 || position>this.length) return false; var node=new Node(element); //在头结点插入 if(position==0) { if(this.head==null) { this.head=node; this.tail=node; } else{ node.next=this.head; this.head.pre=node; this

3-2双向链表

▼魔方 西西 提交于 2019-11-26 10:33:30
双向链表 一种更复杂的链表是“双向链表”或“双面链表”。每个节点有两个链接:一个指向前一个节点,当此节点为第一个节点时,指向空值;而另一个指向下一个节点,当此节点为最后一个节点时,指向空值。 操作 is_empty() 链表是否为空 length() 链表长度 travel() 遍历链表 add(item) 链表头部添加 append(item) 链表尾部添加 insert(pos, item) 指定位置添加 remove(item) 删除节点 search(item) 查找节点是否存在 实现 class Node(object): """双向链表节点""" def __init__(self, item): self.item = item self.next = None self.prev = None class DLinkList(object): """双向链表""" def __init__(self): self._head = None def is_empty(self): """判断链表是否为空""" return self._head == None def length(self): """返回链表的长度""" cur = self._head count = 0 while cur != None: count += 1 cur = cur.next