aboutsummaryrefslogtreecommitdiffstats
path: root/csci1913/Java
diff options
context:
space:
mode:
authorMatthew Strapp <msattr@gmail.com>2019-11-22 08:33:37 -0600
committerMatthew Strapp <msattr@gmail.com>2019-11-22 08:33:37 -0600
commit3b8943e7e802f93e4ca90f4e28cdbb260cc46681 (patch)
tree297ffb70d6c7f7ce9f4b76c870eb43f312855e96 /csci1913/Java
parentMerge branch 'master' of github.com:RosstheRoss/TestingFun (diff)
downloadhomework-3b8943e7e802f93e4ca90f4e28cdbb260cc46681.tar
homework-3b8943e7e802f93e4ca90f4e28cdbb260cc46681.tar.gz
homework-3b8943e7e802f93e4ca90f4e28cdbb260cc46681.tar.bz2
homework-3b8943e7e802f93e4ca90f4e28cdbb260cc46681.tar.lz
homework-3b8943e7e802f93e4ca90f4e28cdbb260cc46681.tar.xz
homework-3b8943e7e802f93e4ca90f4e28cdbb260cc46681.tar.zst
homework-3b8943e7e802f93e4ca90f4e28cdbb260cc46681.zip
Start lab 11
Diffstat (limited to 'csci1913/Java')
-rw-r--r--csci1913/Java/lab11_strap012.java95
1 files changed, 95 insertions, 0 deletions
diff --git a/csci1913/Java/lab11_strap012.java b/csci1913/Java/lab11_strap012.java
new file mode 100644
index 0000000..6b4bbb5
--- /dev/null
+++ b/csci1913/Java/lab11_strap012.java
@@ -0,0 +1,95 @@
+class Deque<Base> {
+ private Node head;
+ private class Node {
+ private Base object;
+ private Node left;
+ private Node right;
+ private Node(Base o,Node l,Node r) {
+ object = o;
+ left = l; right = r;
+ }
+ }
+ public Deque() {
+ head = new Node(null, null, null);
+ head.left=head; head.right=head;
+ }
+ public void enqueueFront(Base object) {
+
+ }
+ public void enqueueRear(Base object) {
+
+ }
+ public Base dequeueFront() {
+
+ }
+ public Base dequeueRear() {
+
+ }
+ public Boolean isEmpty() {
+ return head.right==null && head.left==null;
+ }
+}
+
+// OBSERVATION DEQUE. Test the class DEQUE. 40 points total.
+class ObservationDeque{
+// MAIN. Test the DEQUE on various example arguments.
+ public static void main(String [] args) {
+ Deque<String> deque = new Deque<String>();
+ System.out.println(deque.isEmpty()); // true 2 points.
+ try {
+ System.out.println(deque.dequeueFront());
+ } catch (IllegalStateException ignore) {
+ System.out.println("No dequeueFront."); // No dequeueFront. 2 points.
+ }
+ try { System.out.println(deque.dequeueRear());
+ } catch (IllegalStateException ignore) {
+ System.out.println("No dequeueRear."); // No dequeueRear. 2 points.
+ }
+//Enqueueing to the rear and dequeueing from the rear makes the DEQUE act
+// like a stack.
+ deque.enqueueRear("A");
+ deque.enqueueRear("B");
+ deque.enqueueRear("C");
+
+ System.out.println(deque.isEmpty()); // false 2 points.
+
+ System.out.println(deque.dequeueRear()); // C 2 points.
+ System.out.println(deque.dequeueRear()); // B 2 points.
+ System.out.println(deque.dequeueRear()); // A 2 points.
+ System.out.println(deque.isEmpty()); // true 2 points.
+// Enqueueing to the rear and dequeueing from the front makes the DEQUE act
+// like a queue.
+ deque.enqueueRear("A");
+ deque.enqueueRear("B");
+ deque.enqueueRear("C");
+
+ System.out.println(deque.dequeueFront()); // A 2 points.
+ System.out.println(deque.dequeueFront()); // B 2 points.
+ System.out.println(deque.dequeueFront()); // C 2 points.
+
+ System.out.println(deque.isEmpty()); // true 2 points.
+//Enqueueing to the front and dequeueing from the front makes the DEQUE act
+//like a stack.
+ deque.enqueueFront("A");
+ deque.enqueueFront("B");
+ deque.enqueueFront("C");
+
+ System.out.println(deque.dequeueFront()); // C 2
+ points. System.out.println(deque.dequeueFront()); // B 2 points.
+ System.out.println(deque.dequeueFront()); // A 2 points.
+
+ System.out.println(deque.isEmpty()); // true 2 points.
+
+// Enqueueing to the front and dequeueing from the rear makes the DEQUE act
+// like a queue.
+ deque.enqueueFront("A");
+ deque.enqueueFront("B");
+ deque.enqueueFront("C");
+
+ System.out.println(deque.dequeueRear()); // A 2 points.
+ System.out.println(deque.dequeueRear()); // B 2 points.
+ System.out.println(deque.dequeueRear()); // C 2 points.
+
+ System.out.println(deque.isEmpty()); // true 2 points.
+ }
+} \ No newline at end of file