<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://charlesreid1.com/w/index.php?action=history&amp;feed=atom&amp;title=StacksQueues%2FJava%2FArrayDeque</id>
	<title>StacksQueues/Java/ArrayDeque - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://charlesreid1.com/w/index.php?action=history&amp;feed=atom&amp;title=StacksQueues%2FJava%2FArrayDeque"/>
	<link rel="alternate" type="text/html" href="https://charlesreid1.com/w/index.php?title=StacksQueues/Java/ArrayDeque&amp;action=history"/>
	<updated>2026-06-15T03:50:51Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.39.12</generator>
	<entry>
		<id>https://charlesreid1.com/w/index.php?title=StacksQueues/Java/ArrayDeque&amp;diff=26904&amp;oldid=prev</id>
		<title>Admin: Replacing charlesreid1.com:3000 with git.charlesreid1.com</title>
		<link rel="alternate" type="text/html" href="https://charlesreid1.com/w/index.php?title=StacksQueues/Java/ArrayDeque&amp;diff=26904&amp;oldid=prev"/>
		<updated>2019-10-09T03:53:41Z</updated>

		<summary type="html">&lt;p&gt;Replacing charlesreid1.com:3000 with git.charlesreid1.com&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&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: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 03:53, 9 October 2019&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-l10&quot;&gt;Line 10:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 10:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; 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;==code==&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; 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;==code==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; 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;br/&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; 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;br/&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; 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;Link to the code on git.charlesreid1.com: https://charlesreid1.com&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;:3000&lt;/del&gt;/cs/java/src/master/stacks-queues-deques/queues/ArrayDeque.java&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; 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;Link to the code on git.charlesreid1.com: https://&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;git.&lt;/ins&gt;charlesreid1.com/cs/java/src/master/stacks-queues-deques/queues/ArrayDeque.java&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; 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;br/&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; 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;br/&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; 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;==interface==&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; 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;==interface==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Admin</name></author>
	</entry>
	<entry>
		<id>https://charlesreid1.com/w/index.php?title=StacksQueues/Java/ArrayDeque&amp;diff=17811&amp;oldid=prev</id>
		<title>Admin: /* Notes */</title>
		<link rel="alternate" type="text/html" href="https://charlesreid1.com/w/index.php?title=StacksQueues/Java/ArrayDeque&amp;diff=17811&amp;oldid=prev"/>
		<updated>2017-06-03T21:25:50Z</updated>

		<summary type="html">&lt;p&gt;&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;Notes&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&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: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 21:25, 3 June 2017&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-l4&quot;&gt;Line 4:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 4:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; 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;br/&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; 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;br/&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; 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;implementation details:&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; 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;implementation details:&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; 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;* &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;one option is to have an array that is re-sized and shifted each time the front is removed.&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; 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;* floating head&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;/&lt;/ins&gt;tail index variables &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;and dynamic resizing&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; 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;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;* a better option is to have &lt;/del&gt;floating head &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;and &lt;/del&gt;tail index variables&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;.&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; 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;* &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;dynamic moving also required - &lt;/ins&gt;if head &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;floats &lt;/ins&gt;too far.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; 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;* &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;would then need to check &lt;/del&gt;if head &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;floated &lt;/del&gt;too far.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; 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;* variable or fixed size.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; 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;* &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;can have &lt;/del&gt;variable &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;size array, &lt;/del&gt;or fixed size &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;array&lt;/del&gt;.&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-added&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; 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;br/&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; 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;br/&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; 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;==code==&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; 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;==code==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; 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;br/&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; 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;br/&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; 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;Link to the code on git.charlesreid1.com: https://charlesreid1.com:3000/cs/java/src/master/stacks-queues-deques/queues/&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;ArrayQueue&lt;/del&gt;.java&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; 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;Link to the code on git.charlesreid1.com: https://charlesreid1.com:3000/cs/java/src/master/stacks-queues-deques/queues/&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;ArrayDeque&lt;/ins&gt;.java&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; 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;br/&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; 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;br/&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; 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;==interface==&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; 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;==interface==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; 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;br/&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; 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;br/&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; 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;The methods implemented for a &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;queue &lt;/del&gt;object are:&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; 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;The methods implemented for a &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;deque &lt;/ins&gt;object are:&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; 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;* size() - get the number of elements in the queue&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; 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;* size() - get the number of elements in the queue&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; 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;* isEmpty() - returns true if queue is empty&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; 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;* isEmpty() - returns true if queue is empty&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; 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;* &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;add&lt;/del&gt;() - &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;add the element &lt;/del&gt;to &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;the back of the queue&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; 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;* &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;first&lt;/ins&gt;() - &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;return reference &lt;/ins&gt;to &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;front, but don&amp;#039;t &lt;/ins&gt;remove&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; 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;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;* remove() - &lt;/del&gt;remove &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;and return the element at the front of the queue&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; 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;* &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;last&lt;/ins&gt;() - return reference to &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;back&lt;/ins&gt;, but &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;don&amp;#039;t &lt;/ins&gt;remove&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; 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;* &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;peek&lt;/del&gt;() - return &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;a &lt;/del&gt;reference to &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;the first item in the queue&lt;/del&gt;, but &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;do not &lt;/del&gt;remove &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;it&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; 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;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;* addFront() - add new item to front of &lt;/ins&gt;queue&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; 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; &lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; 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;* &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;addBack&lt;/ins&gt;(&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;) &lt;/ins&gt;- add new &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;item &lt;/ins&gt;to &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;back of queue&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; 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;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;Implementing these for an array based &lt;/del&gt;queue &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;requires us to do the following:&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; 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;* &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;removeFront() &lt;/ins&gt;- remove item from &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;front of &lt;/ins&gt;queue&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; 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;* &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;size - keep track of the size &lt;/del&gt;(&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;tail &lt;/del&gt;- &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;head)&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; 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;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;* removeBack&lt;/ins&gt;() - &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;remove item &lt;/ins&gt;from &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;back of queue&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; 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;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;* &lt;/del&gt;add &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;method - when things are added and we are at capacity, copy &lt;/del&gt;new &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;items into new array (from head cycling through &lt;/del&gt;to &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;tail, in order.)&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-added&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; 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;* &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;remove &lt;/del&gt;- &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;to &lt;/del&gt;remove &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;an &lt;/del&gt;item from &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;the &lt;/del&gt;queue &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;we remove it and increment head by 1 &lt;/del&gt;(&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;much better than the O(n) scooting everything up&lt;/del&gt;)&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-added&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; 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;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;* resize &lt;/del&gt;- &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;allocates a new array, and copies &lt;/del&gt;from &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;old to new from head to tail, resetting index values.&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-added&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; 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;br/&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; 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;br/&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; 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;=Flags=&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; 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;=Flags=&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;

&lt;!-- diff cache key wikidb:diff::1.12:old-17810:rev-17811 --&gt;
&lt;/table&gt;</summary>
		<author><name>Admin</name></author>
	</entry>
	<entry>
		<id>https://charlesreid1.com/w/index.php?title=StacksQueues/Java/ArrayDeque&amp;diff=17810&amp;oldid=prev</id>
		<title>Admin: /* implementation */</title>
		<link rel="alternate" type="text/html" href="https://charlesreid1.com/w/index.php?title=StacksQueues/Java/ArrayDeque&amp;diff=17810&amp;oldid=prev"/>
		<updated>2017-06-03T21:23:41Z</updated>

		<summary type="html">&lt;p&gt;&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;implementation&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;a href=&quot;https://charlesreid1.com/w/index.php?title=StacksQueues/Java/ArrayDeque&amp;amp;diff=17810&amp;amp;oldid=17809&quot;&gt;Show changes&lt;/a&gt;</summary>
		<author><name>Admin</name></author>
	</entry>
	<entry>
		<id>https://charlesreid1.com/w/index.php?title=StacksQueues/Java/ArrayDeque&amp;diff=17809&amp;oldid=prev</id>
		<title>Admin: Created page with &quot;=Notes=  array-based deque (double-ended queue) object.  implementation details: * one option is to have an array that is re-sized and shifted each time the front is removed....&quot;</title>
		<link rel="alternate" type="text/html" href="https://charlesreid1.com/w/index.php?title=StacksQueues/Java/ArrayDeque&amp;diff=17809&amp;oldid=prev"/>
		<updated>2017-06-03T21:23:29Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;=Notes=  array-based deque (double-ended queue) object.  implementation details: * one option is to have an array that is re-sized and shifted each time the front is removed....&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;=Notes=&lt;br /&gt;
&lt;br /&gt;
array-based deque (double-ended queue) object.&lt;br /&gt;
&lt;br /&gt;
implementation details:&lt;br /&gt;
* one option is to have an array that is re-sized and shifted each time the front is removed.&lt;br /&gt;
* a better option is to have floating head and tail index variables.&lt;br /&gt;
* would then need to check if head floated too far.&lt;br /&gt;
* can have variable size array, or fixed size array.&lt;br /&gt;
&lt;br /&gt;
==code==&lt;br /&gt;
&lt;br /&gt;
Link to the code on git.charlesreid1.com: https://charlesreid1.com:3000/cs/java/src/master/stacks-queues-deques/queues/ArrayQueue.java&lt;br /&gt;
&lt;br /&gt;
==interface==&lt;br /&gt;
&lt;br /&gt;
The methods implemented for a queue object are:&lt;br /&gt;
* size() - get the number of elements in the queue&lt;br /&gt;
* isEmpty() - returns true if queue is empty&lt;br /&gt;
* add() - add the element to the back of the queue&lt;br /&gt;
* remove() - remove and return the element at the front of the queue&lt;br /&gt;
* peek() - return a reference to the first item in the queue, but do not remove it&lt;br /&gt;
&lt;br /&gt;
Implementing these for an array based queue requires us to do the following:&lt;br /&gt;
* size - keep track of the size (tail - head)&lt;br /&gt;
* add method - when things are added and we are at capacity, copy new items into new array (from head cycling through to tail, in order.)&lt;br /&gt;
* remove - to remove an item from the queue we remove it and increment head by 1 (much better than the O(n) scooting everything up)&lt;br /&gt;
* resize - allocates a new array, and copies from old to new from head to tail, resetting index values.&lt;br /&gt;
&lt;br /&gt;
==implementation==&lt;br /&gt;
&lt;br /&gt;
The implementation got a bit confusing, mainly because I was trying to save a few bytes here and there. The take-home: you can optimize for bytes til the cows come home, but if it doubles your implementation time, those were some expensive 8-byte savings. Just add a boolean or an extra index - if you need to keep track of the size, use n or size. Especially with floating head and tail pointers - don&amp;#039;t try and do fancy math until you have to.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import java.util.*;&lt;br /&gt;
import java.io.*;&lt;br /&gt;
&lt;br /&gt;
class Empty extends ArrayIndexOutOfBoundsException{};&lt;br /&gt;
&lt;br /&gt;
/**&lt;br /&gt;
 * Array based implementation of a queue.&lt;br /&gt;
 *&lt;br /&gt;
 * methods:&lt;br /&gt;
 *  - toString&lt;br /&gt;
 *  - isEmpty&lt;br /&gt;
 *  - size&lt;br /&gt;
 *  - add&lt;br /&gt;
 *  - remove&lt;br /&gt;
 *  - peek&lt;br /&gt;
 */&lt;br /&gt;
public class ArrayQueue&amp;lt;T&amp;gt; {&lt;br /&gt;
&lt;br /&gt;
	/////////////////////////////////////////////&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
	public static void main(String[] args) { &lt;br /&gt;
		ArrayQueue&amp;lt;Integer&amp;gt; a = new ArrayQueue&amp;lt;Integer&amp;gt;();&lt;br /&gt;
		int na = 17;&lt;br /&gt;
		for(int i=0; i&amp;lt;na; i++) { &lt;br /&gt;
			a.add(i);&lt;br /&gt;
			System.out.println(a);&lt;br /&gt;
		}&lt;br /&gt;
		System.out.println(a);&lt;br /&gt;
		System.out.println(&amp;quot;Added &amp;quot;+na+&amp;quot; items.&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
		int nr = 13;&lt;br /&gt;
		System.out.println(&amp;quot;Removing &amp;quot;+nr+&amp;quot; items.&amp;quot;);&lt;br /&gt;
		for(int j=0; j&amp;lt;nr; j++) {&lt;br /&gt;
			a.remove();&lt;br /&gt;
			System.out.println(a);&lt;br /&gt;
		}&lt;br /&gt;
		System.out.println(a);&lt;br /&gt;
		System.out.println(&amp;quot;Size: &amp;quot;+a.size());&lt;br /&gt;
		&lt;br /&gt;
		try {&lt;br /&gt;
			int many = 1000;&lt;br /&gt;
			System.out.println(&amp;quot;Removing &amp;quot;+many+&amp;quot; items.&amp;quot;);&lt;br /&gt;
			for(int j=0; j&amp;lt;many; j++) {&lt;br /&gt;
				System.out.println(&amp;quot;Size of a is &amp;quot;+a.size()); &lt;br /&gt;
				a.remove();&lt;br /&gt;
				System.out.println(a);&lt;br /&gt;
			}&lt;br /&gt;
			System.out.println(a);&lt;br /&gt;
		} catch(Empty e) {&lt;br /&gt;
			System.out.println(&amp;quot;Caught empty stack exception.&amp;quot;);&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The tests are written to test the add, remove, toString, and size methods, and to check whether we can remove from an empty Queue.&lt;br /&gt;
&lt;br /&gt;
Next come the private fields and constructor:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
	private Object[] data;&lt;br /&gt;
	private int size, head, tail;&lt;br /&gt;
	private boolean empty;&lt;br /&gt;
	private static final int INIT_CAPACITY = 1;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
	public ArrayQueue() {&lt;br /&gt;
		this.head = 0;&lt;br /&gt;
		this.tail = -1;&lt;br /&gt;
		this.size = 0;&lt;br /&gt;
		this.empty = true;&lt;br /&gt;
		this.data = new Object[INIT_CAPACITY];&lt;br /&gt;
	}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The learnings here were again, keep it simple: start with an array of size 1, not of size 10&lt;br /&gt;
&lt;br /&gt;
Keep your variables together, and away from the main method (put the main method at the top or bottom, or in another driver class.)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	public boolean isEmpty() { &lt;br /&gt;
		return empty; &lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	/** Return the size - distance from head to tail - with rotating head and tail positions. */&lt;br /&gt;
	public int size() { &lt;br /&gt;
		return size; &lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	public String toString() { &lt;br /&gt;
		StringBuffer sb = new StringBuffer();&lt;br /&gt;
		sb.append(&amp;quot;[ &amp;quot;);&lt;br /&gt;
		if(isEmpty()) { &lt;br /&gt;
			sb.append(&amp;quot;]&amp;quot;);&lt;br /&gt;
			return sb.toString();&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
		// length &amp;gt;= 1&lt;br /&gt;
		int n = data.length;&lt;br /&gt;
		for(int i=this.head; i!=this.tail; i=(i+1)%n ) { &lt;br /&gt;
			// fencepost&lt;br /&gt;
			if(i!=this.head) { &lt;br /&gt;
				sb.append(&amp;quot;, &amp;quot;);&lt;br /&gt;
			}&lt;br /&gt;
			sb.append(data[i].toString());&lt;br /&gt;
		}&lt;br /&gt;
		sb.append(&amp;quot; ]&amp;quot;);&lt;br /&gt;
		return sb.toString();&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	/** Append an item to the back of the queue */&lt;br /&gt;
	public void add(T e) {&lt;br /&gt;
&lt;br /&gt;
		if(size==data.length) {&lt;br /&gt;
			resize(data.length*2);&lt;br /&gt;
		}&lt;br /&gt;
		tail++;&lt;br /&gt;
		data[tail] = e;&lt;br /&gt;
		size++;&lt;br /&gt;
		this.empty = false;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	public Object remove() throws Empty {&lt;br /&gt;
		if(isEmpty()) {&lt;br /&gt;
			throw new Empty();&lt;br /&gt;
		}&lt;br /&gt;
		Object first = data[head];&lt;br /&gt;
		data[head]=null;&lt;br /&gt;
		head++;&lt;br /&gt;
		size--;&lt;br /&gt;
		if(size==0) {&lt;br /&gt;
			this.empty = true;&lt;br /&gt;
		} else if(size==data.length/4) {&lt;br /&gt;
			resize(data.length/2);&lt;br /&gt;
		}&lt;br /&gt;
		return first;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	private void resize(int newcap) { &lt;br /&gt;
		if(newcap&amp;gt;0) { &lt;br /&gt;
			int n = this.data.length;&lt;br /&gt;
&lt;br /&gt;
			Object[] newdat = new Object[newcap];&lt;br /&gt;
			Object[] olddat = this.data;&lt;br /&gt;
			int k = 0;&lt;br /&gt;
&lt;br /&gt;
			for(int i=this.head; i!=this.tail; i=(i+1)%n ) { &lt;br /&gt;
			    newdat[k] = olddat[i];&lt;br /&gt;
				k++;&lt;br /&gt;
			}&lt;br /&gt;
			newdat[k] = olddat[this.tail];&lt;br /&gt;
&lt;br /&gt;
			this.data = newdat;&lt;br /&gt;
			this.head = 0;&lt;br /&gt;
			this.tail = k;&lt;br /&gt;
			this.size = k+1;&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Flags=&lt;br /&gt;
&lt;br /&gt;
[[Category:Queue]]&lt;br /&gt;
[[Category:Arrays]]&lt;br /&gt;
[[Category:Java]]&lt;br /&gt;
{{DataStructuresFlag}}&lt;/div&gt;</summary>
		<author><name>Admin</name></author>
	</entry>
</feed>