<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>http://www.lensovet.net/~sysadmin/w/index.php?action=history&amp;feed=atom&amp;title=Computer_Science%2F61b%2FHomework%2Fhw4%2Flist%2FDList.java</id>
	<title>Computer Science/61b/Homework/hw4/list/DList.java - Revision history</title>
	<link rel="self" type="application/atom+xml" href="http://www.lensovet.net/~sysadmin/w/index.php?action=history&amp;feed=atom&amp;title=Computer_Science%2F61b%2FHomework%2Fhw4%2Flist%2FDList.java"/>
	<link rel="alternate" type="text/html" href="http://www.lensovet.net/~sysadmin/w/index.php?title=Computer_Science/61b/Homework/hw4/list/DList.java&amp;action=history"/>
	<updated>2026-05-03T06:02:34Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.31.16</generator>
	<entry>
		<id>http://www.lensovet.net/~sysadmin/w/index.php?title=Computer_Science/61b/Homework/hw4/list/DList.java&amp;diff=24317&amp;oldid=prev</id>
		<title>Lensovet: Lensovet moved page CS/61b/Homework/hw4/list/DList.java to Computer Science/61b/Homework/hw4/list/DList.java</title>
		<link rel="alternate" type="text/html" href="http://www.lensovet.net/~sysadmin/w/index.php?title=Computer_Science/61b/Homework/hw4/list/DList.java&amp;diff=24317&amp;oldid=prev"/>
		<updated>2023-02-20T03:51:34Z</updated>

		<summary type="html">&lt;p&gt;Lensovet moved page &lt;a href=&quot;/~sysadmin/w/CS/61b/Homework/hw4/list/DList.java&quot; class=&quot;mw-redirect&quot; title=&quot;CS/61b/Homework/hw4/list/DList.java&quot;&gt;CS/61b/Homework/hw4/list/DList.java&lt;/a&gt; to &lt;a href=&quot;/~sysadmin/w/Computer_Science/61b/Homework/hw4/list/DList.java&quot; title=&quot;Computer Science/61b/Homework/hw4/list/DList.java&quot;&gt;Computer Science/61b/Homework/hw4/list/DList.java&lt;/a&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;Revision as of 03:51, 20 February 2023&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-notice&quot; lang=&quot;en&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(No difference)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Lensovet</name></author>
		
	</entry>
	<entry>
		<id>http://www.lensovet.net/~sysadmin/w/index.php?title=Computer_Science/61b/Homework/hw4/list/DList.java&amp;diff=4005&amp;oldid=prev</id>
		<title>Lensovet: moved CS 61b/Homework/hw4/list/DList.java to CS/61b/Homework/hw4/list/DList.java:&amp;#32;fix cs 61b hierarchy</title>
		<link rel="alternate" type="text/html" href="http://www.lensovet.net/~sysadmin/w/index.php?title=Computer_Science/61b/Homework/hw4/list/DList.java&amp;diff=4005&amp;oldid=prev"/>
		<updated>2010-11-14T06:00:19Z</updated>

		<summary type="html">&lt;p&gt;moved &lt;a href=&quot;/~sysadmin/w/CS_61b/Homework/hw4/list/DList.java&quot; class=&quot;mw-redirect&quot; title=&quot;CS 61b/Homework/hw4/list/DList.java&quot;&gt;CS 61b/Homework/hw4/list/DList.java&lt;/a&gt; to &lt;a href=&quot;/~sysadmin/w/CS/61b/Homework/hw4/list/DList.java&quot; class=&quot;mw-redirect&quot; title=&quot;CS/61b/Homework/hw4/list/DList.java&quot;&gt;CS/61b/Homework/hw4/list/DList.java&lt;/a&gt;: fix cs 61b hierarchy&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;Revision as of 06:00, 14 November 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-notice&quot; lang=&quot;en&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(No difference)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Lensovet</name></author>
		
	</entry>
	<entry>
		<id>http://www.lensovet.net/~sysadmin/w/index.php?title=Computer_Science/61b/Homework/hw4/list/DList.java&amp;diff=2873&amp;oldid=prev</id>
		<title>Lensovet: typo</title>
		<link rel="alternate" type="text/html" href="http://www.lensovet.net/~sysadmin/w/index.php?title=Computer_Science/61b/Homework/hw4/list/DList.java&amp;diff=2873&amp;oldid=prev"/>
		<updated>2007-04-26T22:01:53Z</updated>

		<summary type="html">&lt;p&gt;typo&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;Revision as of 22:01, 26 April 2007&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l1&quot; &gt;Line 1:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;{{code}&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;]&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;{{code}&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;}&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;#160; /* DList.java */&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;#160; /* DList.java */&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;#160; &amp;#160;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;#160; &amp;#160;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Lensovet</name></author>
		
	</entry>
	<entry>
		<id>http://www.lensovet.net/~sysadmin/w/index.php?title=Computer_Science/61b/Homework/hw4/list/DList.java&amp;diff=2872&amp;oldid=prev</id>
		<title>Lensovet at 22:01, 26 April 2007</title>
		<link rel="alternate" type="text/html" href="http://www.lensovet.net/~sysadmin/w/index.php?title=Computer_Science/61b/Homework/hw4/list/DList.java&amp;diff=2872&amp;oldid=prev"/>
		<updated>2007-04-26T22:01:38Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{code}]&lt;br /&gt;
 /* DList.java */&lt;br /&gt;
 &lt;br /&gt;
 package list;&lt;br /&gt;
 &lt;br /&gt;
 /**&lt;br /&gt;
 *  A DList is a mutable doubly-linked list ADT.  Its implementation is&lt;br /&gt;
  *  circularly-linked and employs a sentinel (dummy) node at the head&lt;br /&gt;
  *  of the list.&lt;br /&gt;
  *&lt;br /&gt;
  *  DO NOT CHANGE ANY METHOD PROTOTYPES IN THIS FILE.&lt;br /&gt;
  */&lt;br /&gt;
 &lt;br /&gt;
 public class DList {&lt;br /&gt;
 	&lt;br /&gt;
 	/**&lt;br /&gt;
 	 *  head references the sentinel node.&lt;br /&gt;
 	 *  size is the number of items in the list.  (The sentinel node does not&lt;br /&gt;
 	 *       store an item.)&lt;br /&gt;
 	 *&lt;br /&gt;
 	 *  DO NOT CHANGE THE FOLLOWING FIELD DECLARATIONS.&lt;br /&gt;
 	 */&lt;br /&gt;
 	&lt;br /&gt;
 	protected DListNode head;&lt;br /&gt;
 	protected int size;&lt;br /&gt;
 	&lt;br /&gt;
 	/* DList invariants:&lt;br /&gt;
 	 *  1)  head != null.&lt;br /&gt;
 	 *  2)  For any DListNode x in a DList, x.next != null.&lt;br /&gt;
 	 *  3)  For any DListNode x in a DList, x.prev != null.&lt;br /&gt;
 	 *  4)  For any DListNode x in a DList, if x.next == y, then y.prev == x.&lt;br /&gt;
 	 *  5)  For any DListNode x in a DList, if x.prev == y, then y.next == x.&lt;br /&gt;
 	 *  6)  size is the number of DListNodes, NOT COUNTING the sentinel,&lt;br /&gt;
 	 *      that can be accessed from the sentinel (head) by a sequence of&lt;br /&gt;
 	 *      &amp;quot;next&amp;quot; references.&lt;br /&gt;
 	 */&lt;br /&gt;
 	&lt;br /&gt;
 	/**&lt;br /&gt;
 	 *  newNode() calls the DListNode constructor.  Use this class to allocate&lt;br /&gt;
 	 *  new DListNodes rather than calling the DListNode constructor directly.&lt;br /&gt;
 	 *  That way, only this method needs to be overridden if a subclass of DList&lt;br /&gt;
 	 *  wants to use a different kind of node.&lt;br /&gt;
 	 *  @param item the item to store in the node.&lt;br /&gt;
 	 *  @param prev the node previous to this node.&lt;br /&gt;
 	 *  @param next the node following this node.&lt;br /&gt;
 	 */&lt;br /&gt;
 	protected DListNode newNode(Object item, DListNode prev, DListNode next) {&lt;br /&gt;
 		return new DListNode(item, prev, next);&lt;br /&gt;
 	}&lt;br /&gt;
 	&lt;br /&gt;
 	/**&lt;br /&gt;
 	 *  DList() constructor for an empty DList.&lt;br /&gt;
 	 */&lt;br /&gt;
 	public DList() {&lt;br /&gt;
 		size = 0;&lt;br /&gt;
 		head = newNode(null, null, null);&lt;br /&gt;
 		head.next = head;&lt;br /&gt;
 		head.prev = head;&lt;br /&gt;
 	}&lt;br /&gt;
 	&lt;br /&gt;
 	/**&lt;br /&gt;
 	 *  isEmpty() returns true if this DList is empty, false otherwise.&lt;br /&gt;
 	 *  @return true if this DList is empty, false otherwise. &lt;br /&gt;
 	 *  Performance:  runs in O(1) time.&lt;br /&gt;
 	 */&lt;br /&gt;
 	public boolean isEmpty() {&lt;br /&gt;
 		return size == 0;&lt;br /&gt;
 	}&lt;br /&gt;
 	&lt;br /&gt;
 	/** &lt;br /&gt;
 	 *  length() returns the length of this DList. &lt;br /&gt;
 	 *  @return the length of this DList.&lt;br /&gt;
 	 *  Performance:  runs in O(1) time.&lt;br /&gt;
 	 */&lt;br /&gt;
 	public int length() {&lt;br /&gt;
 		return size;&lt;br /&gt;
 	}&lt;br /&gt;
 	&lt;br /&gt;
 	/**&lt;br /&gt;
 	 *  insertFront() inserts an item at the front of this DList.&lt;br /&gt;
 	 *  @param item is the item to be inserted.&lt;br /&gt;
 	 *  Performance:  runs in O(1) time.&lt;br /&gt;
 	 */&lt;br /&gt;
 	public void insertFront(Object item) {&lt;br /&gt;
 		DListNode node = newNode(item, head, head.next);&lt;br /&gt;
 		head.next.prev = node;&lt;br /&gt;
 		head.next = node;&lt;br /&gt;
 		size++;&lt;br /&gt;
 	}&lt;br /&gt;
 	&lt;br /&gt;
 	/**&lt;br /&gt;
 	 *  insertBack() inserts an item at the back of this DList.&lt;br /&gt;
 	 *  @param item is the item to be inserted.&lt;br /&gt;
 	 *  Performance:  runs in O(1) time.&lt;br /&gt;
 	 */&lt;br /&gt;
 	public void insertBack(Object item) {&lt;br /&gt;
 		DListNode node = newNode(item, head.prev, head);&lt;br /&gt;
 		head.prev.next = node;&lt;br /&gt;
 		head.prev = node;&lt;br /&gt;
 		size++;&lt;br /&gt;
 	}&lt;br /&gt;
 	&lt;br /&gt;
 	/**&lt;br /&gt;
 	 *  front() returns the node at the front of this DList.  If the DList is&lt;br /&gt;
 	 *  empty, return null.&lt;br /&gt;
 	 *&lt;br /&gt;
 	 *  Do NOT return the sentinel under any circumstances!&lt;br /&gt;
 	 *&lt;br /&gt;
 	 *  @return the node at the front of this DList.&lt;br /&gt;
 	 *  Performance:  runs in O(1) time.&lt;br /&gt;
 	 */&lt;br /&gt;
 	public DListNode front() {&lt;br /&gt;
 		if (size == 0) { return null;&lt;br /&gt;
 		} else { return head.next; }&lt;br /&gt;
 	}&lt;br /&gt;
 	&lt;br /&gt;
 	/**&lt;br /&gt;
 	 *  back() returns the node at the back of this DList.  If the DList is&lt;br /&gt;
 	 *  empty, return null.&lt;br /&gt;
 	 *&lt;br /&gt;
 	 *  Do NOT return the sentinel under any circumstances!&lt;br /&gt;
 	 *&lt;br /&gt;
 	 *  @return the node at the back of this DList.&lt;br /&gt;
 	 *  Performance:  runs in O(1) time.&lt;br /&gt;
 	 */&lt;br /&gt;
 	public DListNode back() {&lt;br /&gt;
 		if (size == 0) { return null;&lt;br /&gt;
 		} else { return head.prev; }&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	/**&lt;br /&gt;
 	 *  next() returns the node following &amp;quot;node&amp;quot; in this DList.  If &amp;quot;node&amp;quot; is&lt;br /&gt;
 	 *  null, or &amp;quot;node&amp;quot; is the last node in this DList, return null.&lt;br /&gt;
 	 *&lt;br /&gt;
 	 *  Do NOT return the sentinel under any circumstances!&lt;br /&gt;
 	 *&lt;br /&gt;
 	 *  @param node the node whose successor is sought.&lt;br /&gt;
 	 *  @return the node following &amp;quot;node&amp;quot;.&lt;br /&gt;
 	 *  Performance:  runs in O(1) time.&lt;br /&gt;
 	 */&lt;br /&gt;
 	public DListNode next(DListNode node) {&lt;br /&gt;
 		if (node==null || node.next == head) { return null; }&lt;br /&gt;
 		else { return node.next; }&lt;br /&gt;
 	}&lt;br /&gt;
 	&lt;br /&gt;
 	/**&lt;br /&gt;
 	 *  prev() returns the node prior to &amp;quot;node&amp;quot; in this DList.  If &amp;quot;node&amp;quot; is&lt;br /&gt;
 	 *  null, or &amp;quot;node&amp;quot; is the first node in this DList, return null.&lt;br /&gt;
 	 *&lt;br /&gt;
 	 *  Do NOT return the sentinel under any circumstances!&lt;br /&gt;
 	 *&lt;br /&gt;
 	 *  @param node the node whose predecessor is sought.&lt;br /&gt;
 	 *  @return the node prior to &amp;quot;node&amp;quot;.&lt;br /&gt;
 	 *  Performance:  runs in O(1) time.&lt;br /&gt;
 	 */&lt;br /&gt;
 	public DListNode prev(DListNode node) {&lt;br /&gt;
 		if (node==null || node.prev == head) { return null; }&lt;br /&gt;
 		else { return node.prev; }&lt;br /&gt;
 	}&lt;br /&gt;
 	&lt;br /&gt;
 	/**&lt;br /&gt;
 	 *  insertAfter() inserts an item in this DList immediately following &amp;quot;node&amp;quot;.&lt;br /&gt;
 	 *  If &amp;quot;node&amp;quot; is null, do nothing.&lt;br /&gt;
 	 *  @param item the item to be inserted.&lt;br /&gt;
 	 *  @param node the node to insert the item after.&lt;br /&gt;
 	 *  Performance:  runs in O(1) time.&lt;br /&gt;
 	 */&lt;br /&gt;
 	public void insertAfter(Object item, DListNode node) {&lt;br /&gt;
 		if (node != null) {&lt;br /&gt;
 			DListNode insertion = newNode(item, node, node.next);&lt;br /&gt;
 			node.next.prev = insertion;&lt;br /&gt;
 			node.next = insertion;&lt;br /&gt;
 			size++;&lt;br /&gt;
 		}&lt;br /&gt;
 	}&lt;br /&gt;
 	&lt;br /&gt;
 	/**&lt;br /&gt;
 	 *  insertBefore() inserts an item in this DList immediately before &amp;quot;node&amp;quot;.&lt;br /&gt;
 	 *  If &amp;quot;node&amp;quot; is null, do nothing.&lt;br /&gt;
 	 *  @param item the item to be inserted.&lt;br /&gt;
 	 *  @param node the node to insert the item before.&lt;br /&gt;
 	 *  Performance:  runs in O(1) time.&lt;br /&gt;
 	 */&lt;br /&gt;
 	public void insertBefore(Object item, DListNode node) {&lt;br /&gt;
 		if (node != null) {&lt;br /&gt;
 			DListNode insertion = newNode(item, node.prev, node);&lt;br /&gt;
 			node.prev.next = insertion;&lt;br /&gt;
 			node.prev = insertion;&lt;br /&gt;
 			size++;&lt;br /&gt;
 		}&lt;br /&gt;
 	}&lt;br /&gt;
 	&lt;br /&gt;
 	/**&lt;br /&gt;
 	 *  remove() removes &amp;quot;node&amp;quot; from this DList.  If &amp;quot;node&amp;quot; is null, do nothing.&lt;br /&gt;
 	 *  Performance:  runs in O(1) time.&lt;br /&gt;
 	 */&lt;br /&gt;
 	public void remove(DListNode node) {&lt;br /&gt;
 		if (node != null) {&lt;br /&gt;
 			node.prev.next = node.next;&lt;br /&gt;
 			node.next.prev = node.prev;&lt;br /&gt;
 			// not really necessary, but just to be safe fully disconnect all pointers&lt;br /&gt;
 			node.next = null;&lt;br /&gt;
 			node.prev = null;&lt;br /&gt;
 			size--;&lt;br /&gt;
 		}&lt;br /&gt;
 	}&lt;br /&gt;
 	&lt;br /&gt;
 	/**&lt;br /&gt;
 	 *  toString() returns a String representation of this DList.&lt;br /&gt;
 	 *&lt;br /&gt;
 	 *  DO NOT CHANGE THIS METHOD.&lt;br /&gt;
 	 *&lt;br /&gt;
 	 *  @return a String representation of this DList.&lt;br /&gt;
 	 *  Performance:  runs in O(n) time, where n is the length of the list.&lt;br /&gt;
 	 */&lt;br /&gt;
 	public String toString() {&lt;br /&gt;
 		String result = &amp;quot;[  &amp;quot;;&lt;br /&gt;
 		DListNode current = head.next;&lt;br /&gt;
 		while (current != head) {&lt;br /&gt;
 			result = result + current.item + &amp;quot;  &amp;quot;;&lt;br /&gt;
 			current = current.next;&lt;br /&gt;
 		}&lt;br /&gt;
 		return result + &amp;quot;]&amp;quot;;&lt;br /&gt;
 	}&lt;br /&gt;
 }&lt;/div&gt;</summary>
		<author><name>Lensovet</name></author>
		
	</entry>
</feed>