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

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 閱讀(848) 評論(0)  編輯 收藏 引用 所屬分類: Algorithm
<2010年2月>
31123456
78910111213
14151617181920
21222324252627
28123456
78910111213

常用鏈接

留言簿(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>
            亚洲深夜激情| 欧美自拍偷拍午夜视频| 欧美精品日韩三级| 99re6热在线精品视频播放速度| 蜜臀久久久99精品久久久久久| 久久久久久综合网天天| 亚洲国产小视频| 亚洲精品偷拍| 国产精品视频网站| 葵司免费一区二区三区四区五区| 久久综合激情| 一本久久综合亚洲鲁鲁五月天| 一区二区三区福利| 黄色亚洲网站| 亚洲欧洲日本在线| 国产精品久久久999| 久久精品一区二区三区中文字幕| 久久亚洲精品一区| 一本色道88久久加勒比精品| 香蕉久久夜色| 亚洲另类在线视频| 午夜精品视频一区| 亚洲欧洲综合另类| 亚洲欧美日韩天堂一区二区| 亚洲福利一区| 亚洲综合日韩| 亚洲精品婷婷| 久久精品国产成人| 亚洲一本大道在线| 老色鬼精品视频在线观看播放| 亚洲视频综合| 久久综合色综合88| 欧美一级专区| 欧美日韩国产在线一区| 久久一区欧美| 国产精品一二三四区| 亚洲激情偷拍| 怡红院精品视频| 亚洲欧美日韩国产一区二区| 夜夜嗨av色综合久久久综合网 | 亚洲欧洲日产国码二区| 亚洲无线视频| 99re6这里只有精品| 久久久99精品免费观看不卡| 亚洲欧美日韩国产另类专区| 欧美激情一区二区在线| 久久综合狠狠综合久久综青草| 国产精品v日韩精品| 亚洲激情第一页| **网站欧美大片在线观看| 亚洲在线观看视频| 亚洲尤物视频网| 欧美理论电影在线观看| 欧美激情第9页| 在线观看欧美视频| 久久久久国产精品一区三寸| 久久国产精品久久国产精品| 国产精品美腿一区在线看| 亚洲国产精品视频| 亚洲人成在线影院| 欧美va亚洲va国产综合| 免费成人高清在线视频| 韩国女主播一区二区三区| 香蕉久久a毛片| 久久久久久色| 激情一区二区| 久久视频在线免费观看| 免费看av成人| 1000部国产精品成人观看| 欧美在线精品免播放器视频| 久久se精品一区二区| 国产日韩欧美综合在线| 欧美亚洲尤物久久| 久久综合久久美利坚合众国| 黄色综合网站| 免费在线日韩av| 亚洲精品乱码久久久久| 亚洲先锋成人| 国产午夜精品理论片a级探花| 欧美一区二区三区在| 久热re这里精品视频在线6| 亚洲国产毛片完整版| 欧美国产日韩精品免费观看| 亚洲日本一区二区| 亚洲综合精品| 国产一区二区三区久久精品| 久久久久久久久综合| 亚洲国产精品久久| 亚洲男人天堂2024| 国产真实乱子伦精品视频| 蜜臀99久久精品久久久久久软件| 亚洲人成在线播放网站岛国| 亚洲欧美日韩综合一区| 狠狠综合久久av一区二区老牛| 久热精品视频在线免费观看| 亚洲美女视频在线免费观看| 久久精品日韩欧美| 亚洲人成人99网站| 国产精品日韩精品欧美精品| 久久―日本道色综合久久| 亚洲日本在线观看| 久久成人在线| 一区二区高清视频| 黑人一区二区三区四区五区| 欧美精品一级| 欧美在线免费一级片| 亚洲毛片av| 欧美aa国产视频| 午夜天堂精品久久久久| 亚洲国产欧美一区二区三区同亚洲 | 国产精品扒开腿爽爽爽视频| 午夜综合激情| 日韩视频中文字幕| 免费成人av在线| 午夜精品久久久久久久久久久久 | 欧美日韩国产一区二区| 欧美永久精品| 在线综合亚洲| 亚洲人成77777在线观看网| 午夜欧美不卡精品aaaaa| 日韩一级黄色av| 亚洲国产精品尤物yw在线观看| 国产精品香蕉在线观看| 欧美日韩成人综合| 久久综合色影院| 久久精品国产成人| 性xx色xx综合久久久xx| 一个色综合av| 99精品视频免费全部在线| 欧美激情1区| 蜜臀va亚洲va欧美va天堂 | 亚洲精品黄色| 亚洲第一黄色| 精品91久久久久| 好吊日精品视频| 国产三级欧美三级| 国产日韩精品一区二区三区| 国产精品av免费在线观看| 欧美日韩免费高清| 欧美日韩免费看| 欧美日精品一区视频| 欧美女同在线视频| 欧美日韩高清在线一区| 欧美精品久久久久久久免费观看 | 午夜欧美大片免费观看| 亚洲欧美精品伊人久久| 亚洲小说欧美另类社区| 亚洲深夜激情| 午夜精品久久久久久久| 欧美伊人久久| 久久久久国产精品人| 快射av在线播放一区| 免费日韩视频| 欧美日韩一区二区三区| 国产精品久久毛片a| 国产女主播一区二区三区| 国产一区二区三区最好精华液| 国内外成人免费激情在线视频网站 | 国产日韩欧美视频在线| 国产一区二区高清不卡| 在线观看成人网| 亚洲精品免费在线| 亚洲午夜未删减在线观看| 午夜视频一区二区| 久久亚洲精品一区| 91久久久精品| 亚洲综合导航| 欧美+日本+国产+在线a∨观看| 欧美激情精品久久久久久免费印度 | 亚洲九九爱视频| 亚洲综合好骚| 免费久久99精品国产自在现线| 欧美精品在线一区| 国产精品乱码一区二三区小蝌蚪 | 亚洲国产欧美一区| 亚洲午夜一区二区| 久久久亚洲综合| 亚洲人成在线观看网站高清| 亚洲校园激情| 欧美va亚洲va香蕉在线| 国产精品一区二区视频| 亚洲精品美女| 久久精品国产99| 亚洲欧洲一二三| 久久久xxx| 国产精品女主播| 亚洲片国产一区一级在线观看| 午夜精品视频一区| 亚洲黄色在线观看| 欧美中文字幕精品| 欧美日韩综合一区| 亚洲激情自拍| 久久久久久自在自线| av成人免费| 欧美福利电影网| 韩国av一区二区三区| 亚洲欧美在线x视频| 亚洲人成人一区二区在线观看| 欧美一区激情| 国产女同一区二区|