diff --git a/compsci-lib/src/main/java/dev/obrienlabs/compsci/collections/Stack.java b/compsci-lib/src/main/java/dev/obrienlabs/compsci/collections/Stack.java new file mode 100644 index 0000000..a1ea7cb --- /dev/null +++ b/compsci-lib/src/main/java/dev/obrienlabs/compsci/collections/Stack.java @@ -0,0 +1,70 @@ +package dev.obrienlabs.compsci.collections; + +import java.util.HashMap; +import java.util.Map; +import java.util.stream.Stream; + +public class Stack { + + boolean isBalanced(String s) { + boolean balanced = true; + // index is important + String pushKeys = "[{("; + String pullKeys = "]})"; + Map dictionaryIndex = new HashMap(); + Map dictionaryCost = new HashMap(); + + // initialize lookup map + pushKeys.chars().forEach(x -> dictionaryCost.put(String.valueOf((char)x), Integer.valueOf(1))); + pullKeys.chars().forEach(x -> dictionaryCost.put(String.valueOf((char)x), Integer.valueOf(-1))); + + // initialize stacks + Map stack = new HashMap(); + for(int i=0; i System.out.println(x)); + // lookup dictionary value and add to stack at index - flatmap + // parse both key strings + // use index in dictionary to add to stack + //Stream.of(pushKeys).forEach(x -> { + + //}); + //////Integer index = 0; + //Stream.of(s).forEach(x -> { + for(int index=0; index !x.getValue().equals(0)).count() > 0) + // balanced = true; + //}); + + /*List list = Stream.of(s) + .filter(x -> x.equals(dictionary.get(x))) + .collect(Collectors.toList()); + list.forEach(x -> System.out.println(x));*/ + + return balanced; + } + + public static void main(String[] args) { + Stack stack = new Stack(); + String aString = "{}([()][])"; + System.out.println(stack.isBalanced(aString)); + } +} diff --git a/compsci-lib/src/test/java/dev/obrienlabs/compsci/collections/BinaryTreeTest.java b/compsci-lib/src/test/java/dev/obrienlabs/compsci/collections/BinaryTreeTest.java index 96cf6a0..05b86e7 100644 --- a/compsci-lib/src/test/java/dev/obrienlabs/compsci/collections/BinaryTreeTest.java +++ b/compsci-lib/src/test/java/dev/obrienlabs/compsci/collections/BinaryTreeTest.java @@ -38,6 +38,7 @@ public void testContructor() { StringBuffer buffer = new StringBuffer(); leftList.stream().forEach(x -> buffer.append(x.getData()).append(",")); System.out.println("left nodes: " + tree.printOn(leftList)); + System.out.println("left count: " + Integer.parseInt(Long.toString(leftList.stream().count()))); } } \ No newline at end of file