diff options
author | Matthew Strapp <msattr@gmail.com> | 2019-11-20 07:36:51 -0600 |
---|---|---|
committer | Matthew Strapp <msattr@gmail.com> | 2019-11-20 07:36:51 -0600 |
commit | 7b224dfb10b25653d927fb9ce1b1261c2d308f56 (patch) | |
tree | 033a1847e9b149694860bf556df8355598441480 /csci1913 | |
parent | Start lab (diff) | |
download | homework-7b224dfb10b25653d927fb9ce1b1261c2d308f56.tar homework-7b224dfb10b25653d927fb9ce1b1261c2d308f56.tar.gz homework-7b224dfb10b25653d927fb9ce1b1261c2d308f56.tar.bz2 homework-7b224dfb10b25653d927fb9ce1b1261c2d308f56.tar.lz homework-7b224dfb10b25653d927fb9ce1b1261c2d308f56.tar.xz homework-7b224dfb10b25653d927fb9ce1b1261c2d308f56.tar.zst homework-7b224dfb10b25653d927fb9ce1b1261c2d308f56.zip |
Do lab 10
Diffstat (limited to '')
-rw-r--r-- | csci1913/Java/lab10_strap012.java | 53 |
1 files changed, 46 insertions, 7 deletions
diff --git a/csci1913/Java/lab10_strap012.java b/csci1913/Java/lab10_strap012.java index c8fea79..06c0dfa 100644 --- a/csci1913/Java/lab10_strap012.java +++ b/csci1913/Java/lab10_strap012.java @@ -7,30 +7,69 @@ class AssociationList<Key, Value> { key=k; value=v; next=n; } } + private Node head; public AssociationList() { - Node head = new Node("HEAD", "HEAD", null); + head = new Node(null, null, null); } public void delete(Key key) { + Node left = head; + Node right = head.next; + while (right!=null) { + if (isEqual(right.key, key)) { + left.next=right.next; + break; + } else { + left=right; right=right.next; + } + } } public Value get(Key key) { - + Node where=head.next; + while (where!=null) { + if (isEqual(where.key,key)) { + return where.value; + } else { + where=where.next; + } + } //No matching key found + throw new IllegalArgumentException(); } private boolean isEqual(Key leftKey, Key rightKey) { if (leftKey == null || rightKey == null) { return leftKey == rightKey; } else { - return leftkey.equals(rightKey); + return leftKey.equals(rightKey); } } public boolean isIn(Key key) { - + Node where = head.next; + while (where != null) { + if (isEqual(where.key, key)) { + return true; + } else { + where = where.next; + } + } // No matching key found + return false; } public void put(Key key, Value value) { - + Node where=head.next; + boolean found=false; + while (where!=null){ + if(isEqual(key, where.key)) { + where.value=value; + found=true; + break; + } else { + where=where.next; + } + } //End of while + if (!found) { + Node temp=head.next; + head.next= new Node(key, value, temp); + } } - - } // |