dlist-trailer.html

来自「经典的数据结构源代码(java 实现)」· HTML 代码 · 共 53 行

HTML
53
字号
<html><head><title>Code Fragment</title></head><body text=#000000><center></center><br><br><dl><dd><pre>  <font color=#ff0080>/** Inserts the given node z before the given node v. An error    * occurs if v is the header */</font>  <font color=#8000a0><font color=#8000a0>public</font> </font><font color=#8000a0>void</font> <font color=#0000ff>addBefore</font>(DNode v, <font color=#8000a0>DNode </font>z) <font color=#8000a0><font color=#ff8000>throws</font> </font>IllegalArgumentException {    <font color=#8000a0>DNode </font>u = <font color=#0000ff>getPrev</font>(v);	<font color=#ff0080>// may throw an IllegalArgumentException</font>    z.<font color=#0000ff>setPrev</font>(u);    z.<font color=#0000ff>setNext</font>(v);    v.<font color=#0000ff>setPrev</font>(z);    u.<font color=#0000ff>setNext</font>(z);    size++;  }  <font color=#ff0080>/** Inserts the given node z after the given node v. An error occurs    * if v is the trailer */</font>  <font color=#8000a0><font color=#8000a0>public</font> </font><font color=#8000a0>void</font> <font color=#0000ff>addAfter</font>(DNode v, <font color=#8000a0>DNode </font>z) {    <font color=#8000a0>DNode </font>w = <font color=#0000ff>getNext</font>(v);	<font color=#ff0080>// may throw an IllegalArgumentException</font>    z.<font color=#0000ff>setPrev</font>(v);    z.<font color=#0000ff>setNext</font>(w);    w.<font color=#0000ff>setPrev</font>(z);    v.<font color=#0000ff>setNext</font>(z);    size++;  }  <font color = #ff0080>/** Inserts the given node at the head of the list */</font>  <font color=#8000a0><font color=#8000a0>public</font> </font><font color=#8000a0>void</font> <font color=#0000ff>addFirst</font>(DNode v) {    <font color=#0000ff>addAfter</font>(header, v);  }  <font color = #ff0080>/** Inserts the given node at the tail of the list */</font>  <font color=#8000a0><font color=#8000a0>public</font> </font><font color=#8000a0>void</font> <font color=#0000ff>addLast</font>(DNode v) {    <font color=#0000ff>addBefore</font>(trailer, v);  }  <font color=#ff0080>/** Removes the given node v from the list. An error occurs if v is    * the header or trailer */</font>  <font color=#8000a0><font color=#8000a0>public</font> </font><font color=#8000a0>void</font> <font color=#0000ff>remove</font>(DNode v) {    <font color=#8000a0>DNode </font>u = <font color=#0000ff>getPrev</font>(v);	<font color=#ff0080>// may throw an IllegalArgumentException</font>    <font color=#8000a0>DNode </font>w = <font color=#0000ff>getNext</font>(v);	<font color=#ff0080>// may throw an IllegalArgumentException</font>    <font color=#ff0080>// unlink the node from the list </font>    w.<font color=#0000ff>setPrev</font>(u);    u.<font color=#0000ff>setNext</font>(w);    v.<font color=#0000ff>setPrev</font>(null);    v.<font color=#0000ff>setNext</font>(null);    size--;  }</dl></body></html>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?