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

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) 評(píng)論(0)  編輯 收藏 引用 所屬分類: Algorithm
<2009年11月>
25262728293031
1234567
891011121314
15161718192021
22232425262728
293012345

常用鏈接

留言簿(10)

隨筆分類(307)

隨筆檔案(297)

algorithm

Books_Free_Online

C++

database

Linux

Linux shell

linux socket

misce

  • cloudward
  • 感覺這個(gè)博客還是不錯(cuò),雖然做的東西和我不大相關(guān),覺得看看還是有好處的

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

搜索

  •  

最新評(píng)論

閱讀排行榜

評(píng)論排行榜

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <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>
            久久久精品国产一区二区三区| 国产精品久久久亚洲一区| 欧美激情一区二区三区| 久久米奇亚洲| 欧美 日韩 国产在线| 欧美国产精品中文字幕| 亚洲国产精品久久精品怡红院 | 在线精品国精品国产尤物884a| 激情久久影院| 夜夜嗨av一区二区三区| 亚洲一区久久久| 久久久精品国产99久久精品芒果| 免费不卡在线视频| 日韩西西人体444www| 亚洲欧美日韩在线一区| 久久综合伊人77777蜜臀| 欧美精品日本| 国产在线不卡| 在线亚洲欧美专区二区| 久久久国产视频91| 亚洲人午夜精品| 欧美激情麻豆| 亚洲在线网站| 欧美一区二区三区在线观看视频| 久久久亚洲国产美女国产盗摄| 欧美成人午夜影院| 国产日本亚洲高清| 亚洲日本成人网| 久久久国产视频91| 日韩一级裸体免费视频| 久久九九热免费视频| 欧美色视频一区| 亚洲黄一区二区| 久久久91精品| 亚洲视频一区在线观看| 欧美大片在线观看一区二区| 国产日韩成人精品| 中文欧美日韩| 亚洲国产美女| 久久综合五月| 激情五月婷婷综合| 欧美在线视频日韩| 亚洲无亚洲人成网站77777 | 久久国产一区二区三区| 亚洲精品免费网站| 老鸭窝亚洲一区二区三区| 国产人妖伪娘一区91| 亚洲一级一区| av成人免费在线| 欧美日韩免费视频| 一区二区三区高清在线 | 久久久久久久综合色一本| 欧美小视频在线| 亚洲一区二区三区777| 亚洲精品色婷婷福利天堂| 欧美成人午夜影院| 亚洲精品小视频| 亚洲国产91| 欧美国产极速在线| 99伊人成综合| 一本色道久久综合亚洲精品按摩| 欧美日本韩国| 亚洲一区欧美一区| 亚洲影院高清在线| 韩国v欧美v日本v亚洲v| 久久天天躁狠狠躁夜夜爽蜜月| 欧美在线国产| 亚洲国产视频直播| 亚洲国产日韩精品| 欧美日一区二区三区在线观看国产免| 亚洲一区二区三区乱码aⅴ| 亚洲最新中文字幕| 国产日韩欧美中文| 欧美91大片| 欧美日韩成人一区| 欧美在线国产精品| 久久美女性网| 一区二区av在线| 国产亚洲一区二区三区在线观看| 国产精品亚洲成人| 欧美专区在线观看| 久久精品一级爱片| 亚洲激情影院| 亚洲欧美日韩精品久久| 在线看一区二区| 一区二区三区欧美日韩| 国产亚洲一区二区在线观看| 欧美国产日韩xxxxx| 国产精品国产一区二区 | 久久人人97超碰精品888| 麻豆av福利av久久av| 在线亚洲欧美专区二区| 欧美一区日韩一区| 日韩天堂在线观看| 午夜日韩电影| 在线视频欧美日韩| 久久久久99| 午夜在线一区二区| 欧美高清视频一区| 久久乐国产精品| 国产精品久久久久9999高清| 免费成人在线观看视频| 国产精品每日更新| 91久久精品www人人做人人爽| 国产美女诱惑一区二区| 亚洲精品精选| 亚洲韩国日本中文字幕| 亚洲欧美大片| 亚洲尤物视频网| 欧美精品久久久久a| 麻豆av一区二区三区| 国产精品乱码久久久久久| 亚洲第一在线视频| 一区二区三区在线高清| 亚洲一区bb| 亚洲无玛一区| 欧美精品电影在线| 欧美韩日视频| 亚洲第一福利视频| 午夜日韩在线观看| 午夜精品av| 国产精品成人一区二区| 亚洲精品欧美日韩专区| 亚洲精品在线免费| 免费不卡在线视频| 欧美成人dvd在线视频| 国产一区二区三区最好精华液| 国产精品99久久久久久白浆小说| 亚洲色在线视频| 欧美日韩一区二区视频在线 | 欧美日本精品| 亚洲人午夜精品| 亚洲蜜桃精久久久久久久| 欧美成人激情在线| 亚洲福利国产| 一片黄亚洲嫩模| 欧美亚日韩国产aⅴ精品中极品| 亚洲精品国产品国语在线app| 日韩一区二区精品视频| 99re热这里只有精品视频| 欧美三级网址| 亚洲国产婷婷| 亚洲毛片一区| 欧美日本久久| 一区二区三区高清视频在线观看| 99这里只有精品| 欧美激情女人20p| 亚洲精品社区| 亚洲一区视频在线| 国产精品香蕉在线观看| 亚洲欧美日韩精品一区二区| 久久精品国产精品| **欧美日韩vr在线| 欧美成人r级一区二区三区| 亚洲精品视频一区二区三区| 亚洲一区二区三区在线| 国产欧美一区二区三区在线老狼 | 久久久久久亚洲精品杨幂换脸| 久久这里只精品最新地址| 亚洲电影av在线| 欧美日韩亚洲一区三区| 亚洲欧美日韩综合aⅴ视频| 麻豆精品在线视频| 夜夜嗨av色一区二区不卡| 国产日韩精品电影| 猛男gaygay欧美视频| 一本色道久久精品| 乱中年女人伦av一区二区| 亚洲午夜一区二区| 在线电影欧美日韩一区二区私密| 欧美日韩国产区| 欧美在线综合视频| 亚洲人体影院| 久久免费偷拍视频| 亚洲性感激情| 亚洲福利在线视频| 国产欧美日韩不卡免费| 欧美14一18处毛片| 性久久久久久久久| 日韩视频在线观看一区二区| 久久视频在线免费观看| 亚洲午夜视频| 亚洲人成网站777色婷婷| 国产美女精品免费电影| 欧美日产国产成人免费图片| 久久九九久精品国产免费直播| 一区二区av在线| 亚洲国产精品专区久久 | 亚洲视频1区| 亚洲国产成人久久综合| 久久精品国产亚洲aⅴ| 在线视频一区观看| 亚洲欧洲日韩女同| 亚洲第一页在线| 曰本成人黄色| 精品成人久久| 精品9999| 精品白丝av| 在线精品视频在线观看高清| 国产伦精品一区二区三区视频黑人|