diff options
author | RossTheRoss <msattr@gmail.com> | 2019-11-27 16:44:00 -0600 |
---|---|---|
committer | RossTheRoss <msattr@gmail.com> | 2019-11-27 16:44:00 -0600 |
commit | a7def834fbd801f2e9359eff774dda91eea1490f (patch) | |
tree | 58949c03c67a8515efd5cf391996d18097d85141 /csci1913/Java/lab11_strap012.java | |
parent | What did I even do (diff) | |
download | homework-a7def834fbd801f2e9359eff774dda91eea1490f.tar homework-a7def834fbd801f2e9359eff774dda91eea1490f.tar.gz homework-a7def834fbd801f2e9359eff774dda91eea1490f.tar.bz2 homework-a7def834fbd801f2e9359eff774dda91eea1490f.tar.lz homework-a7def834fbd801f2e9359eff774dda91eea1490f.tar.xz homework-a7def834fbd801f2e9359eff774dda91eea1490f.tar.zst homework-a7def834fbd801f2e9359eff774dda91eea1490f.zip |
End me
Diffstat (limited to '')
-rw-r--r-- | csci1913/Java/lab11_strap012.java | 42 |
1 files changed, 31 insertions, 11 deletions
diff --git a/csci1913/Java/lab11_strap012.java b/csci1913/Java/lab11_strap012.java index 6b4bbb5..7eb146a 100644 --- a/csci1913/Java/lab11_strap012.java +++ b/csci1913/Java/lab11_strap012.java @@ -4,7 +4,7 @@ class Deque<Base> { private Base object; private Node left; private Node right; - private Node(Base o,Node l,Node r) { + private Node(Base o, Node l, Node r) { object = o; left = l; right = r; } @@ -13,20 +13,40 @@ class Deque<Base> { head = new Node(null, null, null); head.left=head; head.right=head; } - public void enqueueFront(Base object) { - - } public void enqueueRear(Base object) { - + Node tempL = head; + Node newNode = new Node(object, tempL.left, tempL); + tempL.left.right = newNode; + tempL.left = newNode; } - public Base dequeueFront() { - + public void enqueueFront(Base object) { + Node tempR = head; + Node newNode = new Node(object, tempR, tempR.right); + tempR.right.left = newNode; + tempR.right = newNode; } public Base dequeueRear() { - + if (isEmpty()) { + throw new IllegalStateException(); + } else { + Node temp = head.left; + temp.left.right = head; + head.left = temp.left; + return temp.object; + } + } + public Base dequeueFront() { + if (isEmpty()) { + throw new IllegalStateException(); + } else { + Node temp = head.right; + temp.right.left = head; + head.right = temp.right; + return temp.object; + } } public Boolean isEmpty() { - return head.right==null && head.left==null; + return head.right==head && head.left==head; } } @@ -74,8 +94,8 @@ class ObservationDeque{ 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()); // 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. |