青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

posts - 297,  comments - 15,  trackbacks - 0

Doubly-linked list

In computer science, a doubly-linked list is a linked data structure that

consists of a set of data records, each having two special link fields that

contain references to the previous and to the next record in the sequence.

It can be viewed as twosingly-linked lists formed from the same data items, 

in two opposite orders. A doubly-linked list whose nodes contains three fields:

      an integer value, the link to the next node, and the link to the previous node.

The two links allow walking along the list in either direction with equal ease.
Compared to a singly-linked list, modifying a doubly-linked list usually requires
changing more pointers, but is sometimes simpler because there is no need to
keep track of the address of the previous node.

Contents

 [hide]

Nomenclature and implementationThe

references stored in the link fields are

usually implemented by pointers; but

(as in any linked data structure) they may also be address offsets or indices into

an array where the nodes live.

The link fields are often called forward and backwards, or next and previous.

A pointer to any node of a doubly-linked list gives access to the whole list. However,

it's usually convenient to handle the list by the pointers of the first and last nodes,

e.g. when passing it to subroutines.

Basic algorithms

Open doubly-linked lists

Data type declarations

 record Node {
data // The data being stored in the node
next // A reference to the next node; null for last node
prev // A reference to the previous node; null for first node
}
 record List {
Node firstNode // points to first node of list; null for empty list
Node lastNode // points to last node of list; null for empty list
}

Iterating over the nodes

Iterating through a doubly linked list can be done in either direction. In fact, direction can

change many times, if desired.

Forwards

 node := list.firstNode
while node ≠ null
<do something with node.data>
node := node.next

Backwards

 node := list.lastNode
while node ≠ null
<do something with node.data>
node := node.prev

Inserting a node

These symmetric functions add a node either after or before a given node, with the

diagram demonstrating after:

Doubly linked list insert after.png
 function insertAfter(List list, Node node, Node newNode)
newNode.prev := node
newNode.next := node.next
if node.next == null
list.lastNode := newNode
else
node.next.prev := newNode
node.next := newNode
 function insertBefore(List list, Node node, Node newNode)
newNode.prev := node.prev
newNode.next := node
if node.prev is null
list.firstNode := newNode
else
node.prev.next := newNode
node.prev := newNode

We also need a function to insert a node at the beginning of a possibly-empty list:

 function insertBeginning(List list, Node newNode)
if list.firstNode == null
list.firstNode := newNode
list.lastNode := newNode
newNode.prev := null
newNode.next := null
else
insertBefore(list, list.firstNode, newNode)

A symmetric function inserts at the end:

 function insertEnd(List list, Node newNode)
if list.lastNode == null
insertBeginning(list, newNode)
else
insertAfter(list, list.lastNode, newNode)

Deleting a node

Removing a node is easier, only requiring care with the firstNode and lastNode:

 function remove(List list, Node node)
if node.prev == null
list.firstNode := node.next
else
node.prev.next := node.next
if node.next == null
list.lastNode := node.prev
else
node.next.prev := node.prev
destroy node

One subtle consequence of this procedure is that deleting the last element of a list

sets both firstNode and lastNode to null, and so it handles removing the last node

from a one-element list correctly. Notice that we also don't need separate "removeBefore"

or "removeAfter" methods, because in a doubly-linked list we can just use "remove(node.prev)"

or "remove(node.next)" where these are valid.

Circular Doubly-linked lists

Iterating over the elements

Assuming that someNode is some node in a non-empty list, this code iterates through

that list starting with someNode (any node will do):

Forwards

 node := someNode
do
do something with node.value
node := node.next
while node ≠ someNode

Backwards

 node := someNode
do
do something with node.value
node := node.prev
while node ≠ someNode

Notice the postponing of the test to the end of the loop. This is important for the

case where the list contains only the single node someNode.

Inserting a node

This simple function inserts a node into a doubly-linked circularly-linked list after

a given element:

 function insertAfter(Node node, Node newNode)
newNode.next := node.next
newNode.prev := node
node.next.prev := newNode
node.next := newNode

To do an "insertBefore", we can simply "insertAfter(node.prev, newNode)". Inserting

an element in a possibly empty list requires a special function:

 function insertEnd(List list, Node node)
if list.lastNode == null
node.prev := node
node.next := node
else
insertAfter(list.lastNode, node)
list.lastNode := node

To insert at the beginning we simply "insertAfter(list.lastNode, node)". Finally,

removing a node must deal with the case where the list empties:

 function remove(List list, Node node)
if node.next == node
list.lastNode := null
else
node.next.prev := node.prev
node.prev.next := node.next
if node == list.lastNode
list.lastNode := node.prev;
destroy node


References

See also

from wikipedia:
http://en.wikipedia.org/wiki/Doubly-linked_list
posted on 2011-01-02 12:04 chatler 閱讀(840) 評論(0)  編輯 收藏 引用 所屬分類: Algorithm
<2009年12月>
293012345
6789101112
13141516171819
20212223242526
272829303112
3456789

常用鏈接

留言簿(10)

隨筆分類(307)

隨筆檔案(297)

algorithm

Books_Free_Online

C++

database

Linux

Linux shell

linux socket

misce

  • cloudward
  • 感覺這個博客還是不錯,雖然做的東西和我不大相關,覺得看看還是有好處的

network

OSS

  • Google Android
  • Android is a software stack for mobile devices that includes an operating system, middleware and key applications. This early look at the Android SDK provides the tools and APIs necessary to begin developing applications on the Android platform using the Java programming language.
  • os161 file list

overall

搜索

  •  

最新評論

閱讀排行榜

評論排行榜

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            国产喷白浆一区二区三区| 伊人精品久久久久7777| 欧美一区二区视频在线观看| 亚洲看片一区| 亚洲视频在线观看| 另类酷文…触手系列精品集v1小说| 依依成人综合视频| 久久久久久久久久久久久9999| 亚洲电影免费| 在线欧美日韩| 亚洲欧美清纯在线制服| 亚洲免费网址| 老色批av在线精品| 日韩一级黄色av| 久久人人爽人人爽| 国产精品色一区二区三区| 国产欧美在线观看| 久久综合久久美利坚合众国| 久久久久九九视频| 影音先锋国产精品| 亚洲综合精品| 亚洲国产欧美在线人成| 久久久久高清| 亚洲日本电影| 亚洲综合色网站| 国产精品爽黄69| 一本综合精品| 久久精品国产99精品国产亚洲性色| 亚洲女优在线| 亚洲国产综合在线| 一区二区三区导航| 国产精品入口尤物| 欧美一级播放| 性欧美精品高清| 国产精品青草久久| 亚洲自拍另类| 久久激情视频| 亚洲国产高清在线观看视频| 欧美a级片网站| 国产欧美日韩伦理| 日韩视频免费观看高清完整版| 毛片一区二区三区| 在线亚洲自拍| 影音先锋一区| 欧美在线观看一二区| 亚洲国产精品一区二区第四页av| 欧美18av| 国产精品美女久久久久久久 | 亚洲免费在线播放| 欧美一区二区三区的| 亚洲九九精品| 六月天综合网| 亚洲一区二区三区高清不卡| 免费观看欧美在线视频的网站| 欧美一区二区三区婷婷月色| 欧美日本一区二区高清播放视频| 正在播放日韩| 亚洲国产精品成人va在线观看| 久久乐国产精品| 亚洲尤物在线| 欧美体内she精视频在线观看| 亚洲国产毛片完整版| 在线成人h网| 葵司免费一区二区三区四区五区| 欧美一区二区日韩一区二区| 久久久久久夜| 性做久久久久久久免费看| 国产精品久久久久久久久免费桃花| 久久天堂精品| 国产精品无人区| 久久成人精品电影| 羞羞色国产精品| 国产欧美精品一区二区三区介绍| 久久一二三四| 最新国产乱人伦偷精品免费网站 | 亚洲欧美在线aaa| 国内精品久久久久久久影视蜜臀| 亚洲欧洲日韩在线| 久久成人综合视频| 日韩视频中文字幕| 国产精品v日韩精品v欧美精品网站 | 久久福利一区| 亚洲欧洲日韩在线| 欧美大片免费观看| 鲁大师成人一区二区三区| 亚洲精品国产品国语在线app| 国产精品久久久久国产精品日日| 久久久91精品国产一区二区三区 | 欧美一级在线播放| 欧美有码在线观看视频| 国内成人精品2018免费看| 日韩视频在线播放| 久久九九精品99国产精品| 一区二区三区精品久久久| 中文日韩在线| 欧美在线精品一区| 一本大道久久精品懂色aⅴ| 亚洲国产精品va在看黑人| 国产精品成av人在线视午夜片| 美女日韩在线中文字幕| 一本色道久久88综合亚洲精品ⅰ | 国产综合视频| 欧美日本韩国| 久久天天躁夜夜躁狠狠躁2022 | 亚洲一本视频| 国产精品专区h在线观看| 欧美成人免费网| 亚洲国产高清在线| 亚洲伦理网站| 在线观看av不卡| 国产在线欧美| 99精品国产在热久久| 亚洲一区二区三区免费观看 | 亚洲破处大片| 亚洲国产精品福利| 亚洲精品在线观看免费| 亚洲国产高清视频| 一区二区三区www| 最新高清无码专区| 亚洲国产电影| 亚洲精品黄色| 欧美一区二区三区四区视频 | 久久精品视频在线看| 久久久久久成人| 亚洲一区二区免费| 欧美专区在线观看一区| 欧美国产日韩a欧美在线观看| 亚洲精品中文字幕在线| 久久国产66| 欧美激情一区三区| 韩国三级在线一区| 一区二区三区欧美| 快播亚洲色图| 欧美大片免费观看| 黄色成人91| 日韩视频精品在线| 欧美一二区视频| 亚洲国产美女久久久久| 欧美一级二级三级蜜桃| 卡一卡二国产精品| 亚洲高清av在线| 欧美在线视频一区二区| 国产欧美在线看| 在线成人av网站| 性欧美超级视频| 99国产精品久久久久老师| 久久综合久久综合久久综合| 亚洲第一中文字幕在线观看| 亚洲一区影院| 亚洲国产高清一区二区三区| 亚洲一区二区三区精品在线| 尤物yw午夜国产精品视频明星| 亚洲欧美激情视频| 欧美日韩不卡| 亚洲麻豆视频| 欧美一区二区三区四区高清| 欧美一级理论片| 欧美日韩无遮挡| 久久国产欧美| 欧美大片在线观看一区二区| 99re热精品| 亚洲自拍啪啪| 99热免费精品| 亚洲主播在线观看| 亚洲国产精品成人综合| 亚洲视频网在线直播| 黑人操亚洲美女惩罚| 免费不卡在线观看| 国产精品区免费视频| 欧美剧在线免费观看网站| 亚洲欧美成人网| 久久久亚洲人| 久久精品五月婷婷| 国产日韩专区| 欧美日韩高清在线| 一区二区三区四区五区视频 | 亚洲一区二区三区影院| 国产精品国产馆在线真实露脸| 欧美电影免费观看高清| 国产欧美日韩三级| 亚洲精品1234| 亚洲电影欧美电影有声小说| 亚洲香蕉网站| 在线综合欧美| 午夜视频一区| 欧美绝品在线观看成人午夜影视| 久久中文精品| 国产综合精品| 亚洲午夜小视频| 西西人体一区二区| 国产精品一区二区三区四区 | 亚洲欧美日韩国产中文| 久久久亚洲综合| 国产亚洲福利社区一区| 午夜精品三级视频福利| 久久成人国产| 国产欧美日韩高清| 亚洲男女自偷自拍| 羞羞漫画18久久大片| 韩国一区二区三区在线观看|