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

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>
            欧美一区二区视频免费观看| 久久精品国产99精品国产亚洲性色| 99热免费精品| 欧美大片在线影院| 另类天堂av| 国产一区二区三区精品久久久| 欧美黄色免费网站| 亚洲私拍自拍| 久久香蕉国产线看观看av| 国产日韩精品一区二区| 免费在线成人av| 99re8这里有精品热视频免费 | 亚洲高清不卡一区| 欧美欧美全黄| 亚洲视频1区| 久久久久久久一区二区| 国产一区二区三区久久久久久久久 | 久久综合中文色婷婷| 欧美成人在线网站| 亚洲欧美久久久久一区二区三区| 亚洲一区二区在线播放| 黑人巨大精品欧美黑白配亚洲| 一区二区三区在线看| 国产乱码精品一区二区三| 欧美freesex交免费视频| 久久电影一区| 国产精品v一区二区三区| 91久久精品国产91性色tv| 亚洲精品视频在线播放| 国产深夜精品福利| 国产精品夜夜夜| 国产一区99| 亚洲肉体裸体xxxx137| 99视频热这里只有精品免费| 一区二区激情小说| 欧美一区二区在线视频| 久久九九免费| 亚洲精品少妇| 香蕉成人伊视频在线观看| 国产精品自拍三区| 欧美精品日韩一本| 亚洲韩日在线| 久久精品一区四区| 国内精品一区二区| 久久亚洲综合网| 久久久噜噜噜久久| 亚洲女同精品视频| 欧美一区二区三区免费大片| 红桃视频成人| 亚洲一区二区精品在线观看| 亚洲日本欧美在线| 久久综合伊人77777麻豆| 亚洲欧美日韩在线观看a三区| 亚洲视频一区在线| 亚洲在线免费| 久久午夜精品| 午夜精品婷婷| 香蕉久久一区二区不卡无毒影院 | 亚洲欧美综合国产精品一区| 亚洲一区二区免费视频| 中日韩高清电影网| 欧美伊人影院| 亚洲精品美女在线观看| 欧美伊久线香蕉线新在线| 欧美精品v日韩精品v国产精品 | 久久视频国产精品免费视频在线| 国产欧美日韩不卡免费| 性色av一区二区三区红粉影视| 亚洲欧洲一区二区在线播放| 久久精品水蜜桃av综合天堂| 亚洲一区二区三| 亚洲国产精品悠悠久久琪琪| 久久免费视频在线| 欧美一级黄色网| 国产精品精品视频| 亚洲最新视频在线| 亚洲人成在线观看网站高清| 99热在这里有精品免费| 欧美裸体一区二区三区| 亚洲精品久久久久久久久久久久久| 亚洲欧美日韩第一区| 亚洲——在线| 亚洲电影第1页| 乱人伦精品视频在线观看| 亚洲欧美国产日韩天堂区| 国产精品videossex久久发布| 在线精品一区| 欧美福利影院| 午夜欧美精品| 亚洲国产国产亚洲一二三| 亚洲高清在线精品| 欧美成人第一页| 国产伦精品一区二区三区| 久久久久久电影| 国外成人在线| 久久超碰97中文字幕| 久久久久久久网| 激情懂色av一区av二区av| 久久精品国产第一区二区三区最新章节| 亚洲欧美日韩精品久久久| 欧美成人亚洲成人| 久久婷婷av| 亚洲特黄一级片| 欧美激情亚洲国产| 亚洲日韩中文字幕在线播放| 亚洲一区二区日本| 欧美一级久久久久久久大片| 国产精品中文字幕在线观看| 久久国产精品黑丝| 亚洲视频播放| 久久九九精品99国产精品| 亚洲人成网在线播放| 亚洲欧美成人综合| 欧美在线短视频| 亚洲日本黄色| 欧美亚洲一区二区在线| 影音先锋中文字幕一区二区| 欧美日韩第一页| 99www免费人成精品| 麻豆国产va免费精品高清在线| 99精品欧美一区| a91a精品视频在线观看| 亚洲国产精品综合| 国内精品99| 亚洲人久久久| 久久久最新网址| 亚洲激情视频在线播放| 欧美风情在线观看| 亚洲成色www8888| 欧美成人免费大片| 麻豆av一区二区三区久久| 久久精品一区二区三区不卡| 日韩午夜黄色| 亚洲一区免费看| 亚洲黄色成人久久久| 亚洲高清免费在线| 亚洲第一页自拍| 亚洲一卡久久| 日韩一区二区高清| 久久久久久**毛片大全| 久久久久免费| 欧美私人网站| 一色屋精品视频免费看| 亚洲国产日韩精品| 亚洲电影专区| 久久精品成人欧美大片古装| 噜噜噜在线观看免费视频日韩| 免费欧美日韩| 一区二区三区视频免费在线观看| 亚洲一级片在线看| 欧美大片在线影院| 国产精品久久久一区麻豆最新章节| 国产精品国产一区二区| 精品动漫3d一区二区三区免费版 | 亚洲一区二区免费看| 欧美影院在线| 亚洲高清久久久| 午夜精品久久久| 欧美视频在线观看一区二区| 一区二区三区中文在线观看 | 欧美影院视频| 日韩系列欧美系列| aⅴ色国产欧美| 亚洲国产精品成人久久综合一区| 亚洲欧美日韩国产精品| 欧美成人午夜77777| 一区二区三区我不卡| 久久国产日韩| 欧美一区二区三区免费大片| 久久综合久久88| 午夜精品电影| 国产亚洲精品bv在线观看| 久久久久国产精品午夜一区| 一区二区三区免费看| 国产精品白丝av嫩草影院| 亚洲天堂男人| 翔田千里一区二区| 欧美精品在线一区二区三区| 亚洲国产婷婷综合在线精品 | 久久香蕉国产线看观看网| 亚洲电影自拍| 99爱精品视频| 欧美日韩一二区| 久久精品亚洲精品| 欧美不卡激情三级在线观看| 91久久黄色| 亚洲欧美日韩区| 亚洲美女视频| 亚洲欧美一区二区在线观看| 亚洲高清不卡在线| 99精品国产高清一区二区| 精品成人久久| 麻豆精品视频| 亚洲国产视频a| 亚洲理论在线观看| 欧美日韩国产美| 中国成人黄色视屏| 午夜亚洲福利在线老司机| 国产精品福利在线| 性色av一区二区三区|