├── LICENSE ├── Readme.md ├── Software and hardware list.pdf ├── compile.bat ├── compile.sh ├── mods ├── com.example.build │ ├── com │ │ └── example │ │ │ └── build │ │ │ └── Builder.class │ └── module-info.class ├── com.example.datastructure.chapter_01_ │ ├── com │ │ └── example │ │ │ └── datastructure │ │ │ └── SimplePowerRemainderComputation.class │ └── module-info.class ├── com.example.datastructure.chapter_02_ │ ├── com │ │ └── example │ │ │ └── datastructure │ │ │ ├── Array.class │ │ │ ├── CircularLinkedList.class │ │ │ ├── DecimalInteger.class │ │ │ ├── DoublyLinkedList$DoublyLinkedNode.class │ │ │ ├── DoublyLinkedList$ReverseListIterator.class │ │ │ ├── DoublyLinkedList.class │ │ │ ├── LinkedList$ListIterator.class │ │ │ ├── LinkedList$Node.class │ │ │ ├── LinkedList.class │ │ │ └── OrderedPair.class │ └── module-info.class ├── com.example.datastructure.chapter_03_ │ ├── com │ │ └── example │ │ │ └── adt │ │ │ ├── DoubleEndedQueue.class │ │ │ ├── DoubleEndedQueueImplArray.class │ │ │ ├── DoubleEndedQueueImplLinkedList.class │ │ │ ├── NoSpaceException.class │ │ │ ├── OrderedStore.class │ │ │ ├── Queue.class │ │ │ ├── QueueImplArray$1.class │ │ │ ├── QueueImplArray.class │ │ │ ├── QueueImplLinkedList.class │ │ │ ├── Stack.class │ │ │ ├── StackImplArray$1.class │ │ │ ├── StackImplArray.class │ │ │ └── StackImplLinkedList.class │ └── module-info.class ├── com.example.datastructure.chapter_04_ │ ├── com │ │ └── example │ │ │ └── functional │ │ │ ├── Address.class │ │ │ ├── BinomialForest$BinomialTree.class │ │ │ ├── BinomialForest$CombinationBinomialTree.class │ │ │ ├── BinomialForest.class │ │ │ ├── City.class │ │ │ ├── Country.class │ │ │ ├── FunctionalExamples$1StackFrame.class │ │ │ ├── FunctionalExamples.class │ │ │ ├── FunctionalInterfaceWithDefaultMethod.class │ │ │ ├── LinkedList$EmptyList.class │ │ │ ├── LinkedList.class │ │ │ ├── NoArgumentExpression.class │ │ │ ├── NoArgumentExpressionWithException.class │ │ │ ├── NoValueException.class │ │ │ ├── OneArgumentExpression.class │ │ │ ├── OneArgumentExpressionWithException.class │ │ │ ├── OneArgumentStatement.class │ │ │ ├── OneArgumentStatementWithException.class │ │ │ ├── Option$None.class │ │ │ ├── Option$Some.class │ │ │ ├── Option.class │ │ │ ├── Person.class │ │ │ ├── SampleFunctionalInterface.class │ │ │ ├── ThreeArgumentStatement.class │ │ │ ├── Try$Failure.class │ │ │ ├── Try$Success.class │ │ │ ├── Try.class │ │ │ ├── TwoArgumentExpression.class │ │ │ └── TwoArgumentStatement.class │ └── module-info.class ├── com.example.datastructure.chapter_05_ │ ├── com │ │ └── example │ │ │ └── search │ │ │ ├── ArraySearcher.class │ │ │ └── ArraySorter.class │ └── module-info.class ├── com.example.datastructure.chapter_06_ │ ├── com │ │ └── example │ │ │ └── sort │ │ │ ├── ArraySorter.class │ │ │ └── OrderedPair.class │ └── module-info.class ├── com.example.datastructure.chapter_07_ │ ├── com │ │ └── example │ │ │ └── tree │ │ │ ├── BinaryTree$1StackFame.class │ │ │ ├── BinaryTree$1StackFrame.class │ │ │ ├── BinaryTree$2StackFame.class │ │ │ ├── BinaryTree$DepthFirstTraversalType.class │ │ │ ├── BinaryTree$Node.class │ │ │ ├── BinaryTree.class │ │ │ ├── FunctionalTree.class │ │ │ ├── Tree$1.class │ │ │ ├── Tree$Node.class │ │ │ └── Tree.class │ └── module-info.class ├── com.example.datastructure.chapter_08_ │ ├── com │ │ └── example │ │ │ └── searchtree │ │ │ ├── AVLTree$Node.class │ │ │ ├── AVLTree.class │ │ │ ├── BinarySearchTree.class │ │ │ ├── RedBlackTree$Node.class │ │ │ └── RedBlackTree.class │ └── module-info.class ├── com.example.datastructure.chapter_09_ │ ├── com │ │ └── example │ │ │ └── priorityqueue │ │ │ ├── ArrayHeap$1.class │ │ │ ├── ArrayHeap.class │ │ │ ├── BinomialForest$BinomialTree.class │ │ │ ├── BinomialForest.class │ │ │ ├── LinkedHeap$Node.class │ │ │ ├── LinkedHeap.class │ │ │ ├── LinkedList$ListIterator.class │ │ │ ├── LinkedList$Node.class │ │ │ ├── LinkedList.class │ │ │ ├── PriorityQueue.class │ │ │ └── SortableLinkedList.class │ └── module-info.class ├── com.example.datastructure.chapter_10_ │ ├── com │ │ └── example │ │ │ └── graph │ │ │ ├── AdjacencyListGraphWithDenseVertex$Edge.class │ │ │ ├── AdjacencyListGraphWithDenseVertex$Vertex.class │ │ │ ├── AdjacencyListGraphWithDenseVertex.class │ │ │ ├── AdjacencyListGraphWithSparseVertex$Edge.class │ │ │ ├── AdjacencyListGraphWithSparseVertex$Vertex.class │ │ │ ├── AdjacencyListGraphWithSparseVertex.class │ │ │ ├── AdjacencyMatrixGraphWithDenseVertex$1.class │ │ │ ├── AdjacencyMatrixGraphWithDenseVertex$NullValue.class │ │ │ ├── AdjacencyMatrixGraphWithDenseVertex$Vertex.class │ │ │ ├── AdjacencyMatrixGraphWithDenseVertex.class │ │ │ ├── AdjacencyMatrixGraphWithSparseVertex$1.class │ │ │ ├── AdjacencyMatrixGraphWithSparseVertex$NullEdgeValue.class │ │ │ ├── AdjacencyMatrixGraphWithSparseVertex.class │ │ │ ├── CycleDetectedException.class │ │ │ ├── Graph$1.class │ │ │ ├── Graph$CostEdge.class │ │ │ ├── Graph$Edge.class │ │ │ ├── Graph$TraversalType.class │ │ │ ├── Graph.class │ │ │ ├── GraphVertex.class │ │ │ ├── UnionFind$Node.class │ │ │ └── UnionFind.class │ └── module-info.class └── com.example.datastructure.chapter_11_ │ ├── com │ └── example │ │ └── reactive │ │ ├── Consumer.class │ │ ├── EventConsumer$1.class │ │ ├── EventConsumer$ConsumerCodeContainer.class │ │ ├── EventConsumer$StreamEvent.class │ │ ├── EventConsumer.class │ │ ├── EventStream$1.class │ │ ├── EventStream$2.class │ │ ├── EventStream$3.class │ │ ├── EventStream$4.class │ │ ├── EventStream.class │ │ ├── FileReader.class │ │ ├── FilterTask.class │ │ ├── FriendCountProblem.class │ │ ├── MapperTask.class │ │ ├── PerfectNumberTest$1.class │ │ ├── PerfectNumberTest.class │ │ ├── ProcessorTask.class │ │ ├── ProducerConsumerGarbageFreeQueue$1.class │ │ ├── ProducerConsumerGarbageFreeQueue$1MutableInteger.class │ │ ├── ProducerConsumerGarbageFreeQueue$Event.class │ │ ├── ProducerConsumerGarbageFreeQueue$EventType.class │ │ ├── ProducerConsumerGarbageFreeQueue.class │ │ ├── ProducerConsumerQueue$1.class │ │ ├── ProducerConsumerQueue$Event.class │ │ ├── ProducerConsumerQueue$EventType.class │ │ ├── ProducerConsumerQueue.class │ │ ├── SemaphoreExample.class │ │ ├── Task.class │ │ ├── ThreadSafeCounter.class │ │ ├── ThreadSafeFixedLengthBlockingQueue.class │ │ ├── ThreadSafeFixedLengthSpinlockGarbageFreeQueue.class │ │ └── ThreadSafeFixedLengthSpinlockQueue.class │ └── module-info.class └── src ├── com.example.build ├── com │ └── example │ │ └── build │ │ └── Builder.java └── module-info.java ├── com.example.datastructure.chapter_01_ ├── com │ └── example │ │ └── datastructure │ │ └── SimplePowerRemainderComputation.java └── module-info.java ├── com.example.datastructure.chapter_02_ ├── com │ └── example │ │ └── datastructure │ │ ├── Array.java │ │ ├── CircularLinkedList.java │ │ ├── DecimalInteger.java │ │ ├── DoublyLinkedList.java │ │ ├── LinkedList.java │ │ └── OrderedPair.java └── module-info.java ├── com.example.datastructure.chapter_03_ ├── com │ └── example │ │ └── adt │ │ ├── DoubleEndedQueue.java │ │ ├── DoubleEndedQueueImplArray.java │ │ ├── DoubleEndedQueueImplLinkedList.java │ │ ├── NoSpaceException.java │ │ ├── OrderedStore.java │ │ ├── Queue.java │ │ ├── QueueImplArray.java │ │ ├── QueueImplLinkedList.java │ │ ├── Stack.java │ │ ├── StackImplArray.java │ │ └── StackImplLinkedList.java └── module-info.java ├── com.example.datastructure.chapter_04_ ├── com │ └── example │ │ └── functional │ │ ├── Address.java │ │ ├── BinomialForest.java │ │ ├── City.java │ │ ├── Country.java │ │ ├── FunctionalExamples.java │ │ ├── FunctionalInterfaceWithDefaultMethod.java │ │ ├── LinkedList.java │ │ ├── NoArgumentExpression.java │ │ ├── NoArgumentExpressionWithException.java │ │ ├── NoValueException.java │ │ ├── OneArgumentExpression.java │ │ ├── OneArgumentExpressionWithException.java │ │ ├── OneArgumentStatement.java │ │ ├── OneArgumentStatementWithException.java │ │ ├── Option.java │ │ ├── Person.java │ │ ├── SampleFunctionalInterface.java │ │ ├── ThreeArgumentStatement.java │ │ ├── Try.java │ │ ├── TwoArgumentExpression.java │ │ └── TwoArgumentStatement.java └── module-info.java ├── com.example.datastructure.chapter_05_ ├── com │ └── example │ │ └── search │ │ ├── ArraySearcher.java │ │ └── ArraySorter.java └── module-info.java ├── com.example.datastructure.chapter_06_ ├── com │ └── example │ │ └── sort │ │ ├── ArraySorter.java │ │ └── OrderedPair.java └── module-info.java ├── com.example.datastructure.chapter_07_ ├── com │ └── example │ │ └── tree │ │ ├── BinaryTree.java │ │ ├── FunctionalTree.java │ │ └── Tree.java └── module-info.java ├── com.example.datastructure.chapter_08_ ├── com │ └── example │ │ └── searchtree │ │ ├── AVLTree.java │ │ ├── BinarySearchTree.java │ │ └── RedBlackTree.java └── module-info.java ├── com.example.datastructure.chapter_09_ ├── com │ └── example │ │ └── priorityqueue │ │ ├── ArrayHeap.java │ │ ├── BinomialForest.java │ │ ├── LinkedHeap.java │ │ ├── PriorityQueue.java │ │ └── SortableLinkedList.java └── module-info.java ├── com.example.datastructure.chapter_10_ ├── com │ └── example │ │ └── graph │ │ ├── AdjacencyListGraphWithDenseVertex.java │ │ ├── AdjacencyListGraphWithSparseVertex.java │ │ ├── AdjacencyMatrixGraphWithDenseVertex.java │ │ ├── AdjacencyMatrixGraphWithSparseVertex.java │ │ ├── CycleDetectedException.java │ │ ├── Graph.java │ │ ├── GraphVertex.java │ │ └── UnionFind.java └── module-info.java └── com.example.datastructure.chapter_11_ ├── com └── example │ └── reactive │ ├── Consumer.java │ ├── EventConsumer.java │ ├── EventStream.java │ ├── FileReader.java │ ├── FilterTask.java │ ├── FriendCountProblem.java │ ├── MapperTask.java │ ├── PerfectNumberTest.java │ ├── ProcessorTask.java │ ├── ProducerConsumerGarbageFreeQueue.java │ ├── ProducerConsumerQueue.java │ ├── SemaphoreExample.java │ ├── Task.java │ ├── ThreadSafeCounter.java │ ├── ThreadSafeFixedLengthBlockingQueue.java │ ├── ThreadSafeFixedLengthSpinlockGarbageFreeQueue.java │ └── ThreadSafeFixedLengthSpinlockQueue.java └── module-info.java /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Packt 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Readme.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | ### Download a free PDF 5 | 6 | If you have already purchased a print or Kindle version of this book, you can get a DRM-free PDF version at no cost.
Simply click on the link to claim your free PDF.
7 |

https://packt.link/free-ebook/9781785889349

-------------------------------------------------------------------------------- /Software and hardware list.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/Software and hardware list.pdf -------------------------------------------------------------------------------- /compile.bat: -------------------------------------------------------------------------------- 1 | javac -d mods --module-source-path src src\com.example.build\module-info.java src\com.example.build\com\example\build\Builder.java 2 | java --module-path mods -m com.example.build/com.example.build.Builder 3 | -------------------------------------------------------------------------------- /compile.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | javac -d mods --module-source-path src $(find src -name "*.java") 4 | -------------------------------------------------------------------------------- /mods/com.example.build/com/example/build/Builder.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.build/com/example/build/Builder.class -------------------------------------------------------------------------------- /mods/com.example.build/module-info.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.build/module-info.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_01_/com/example/datastructure/SimplePowerRemainderComputation.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_01_/com/example/datastructure/SimplePowerRemainderComputation.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_01_/module-info.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_01_/module-info.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_02_/com/example/datastructure/Array.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_02_/com/example/datastructure/Array.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_02_/com/example/datastructure/CircularLinkedList.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_02_/com/example/datastructure/CircularLinkedList.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_02_/com/example/datastructure/DecimalInteger.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_02_/com/example/datastructure/DecimalInteger.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_02_/com/example/datastructure/DoublyLinkedList$DoublyLinkedNode.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_02_/com/example/datastructure/DoublyLinkedList$DoublyLinkedNode.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_02_/com/example/datastructure/DoublyLinkedList$ReverseListIterator.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_02_/com/example/datastructure/DoublyLinkedList$ReverseListIterator.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_02_/com/example/datastructure/DoublyLinkedList.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_02_/com/example/datastructure/DoublyLinkedList.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_02_/com/example/datastructure/LinkedList$ListIterator.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_02_/com/example/datastructure/LinkedList$ListIterator.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_02_/com/example/datastructure/LinkedList$Node.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_02_/com/example/datastructure/LinkedList$Node.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_02_/com/example/datastructure/LinkedList.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_02_/com/example/datastructure/LinkedList.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_02_/com/example/datastructure/OrderedPair.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_02_/com/example/datastructure/OrderedPair.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_02_/module-info.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_02_/module-info.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_03_/com/example/adt/DoubleEndedQueue.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_03_/com/example/adt/DoubleEndedQueue.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_03_/com/example/adt/DoubleEndedQueueImplArray.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_03_/com/example/adt/DoubleEndedQueueImplArray.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_03_/com/example/adt/DoubleEndedQueueImplLinkedList.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_03_/com/example/adt/DoubleEndedQueueImplLinkedList.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_03_/com/example/adt/NoSpaceException.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_03_/com/example/adt/NoSpaceException.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_03_/com/example/adt/OrderedStore.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_03_/com/example/adt/OrderedStore.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_03_/com/example/adt/Queue.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_03_/com/example/adt/Queue.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_03_/com/example/adt/QueueImplArray$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_03_/com/example/adt/QueueImplArray$1.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_03_/com/example/adt/QueueImplArray.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_03_/com/example/adt/QueueImplArray.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_03_/com/example/adt/QueueImplLinkedList.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_03_/com/example/adt/QueueImplLinkedList.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_03_/com/example/adt/Stack.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_03_/com/example/adt/Stack.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_03_/com/example/adt/StackImplArray$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_03_/com/example/adt/StackImplArray$1.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_03_/com/example/adt/StackImplArray.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_03_/com/example/adt/StackImplArray.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_03_/com/example/adt/StackImplLinkedList.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_03_/com/example/adt/StackImplLinkedList.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_03_/module-info.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_03_/module-info.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_04_/com/example/functional/Address.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_04_/com/example/functional/Address.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_04_/com/example/functional/BinomialForest$BinomialTree.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_04_/com/example/functional/BinomialForest$BinomialTree.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_04_/com/example/functional/BinomialForest$CombinationBinomialTree.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_04_/com/example/functional/BinomialForest$CombinationBinomialTree.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_04_/com/example/functional/BinomialForest.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_04_/com/example/functional/BinomialForest.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_04_/com/example/functional/City.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_04_/com/example/functional/City.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_04_/com/example/functional/Country.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_04_/com/example/functional/Country.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_04_/com/example/functional/FunctionalExamples$1StackFrame.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_04_/com/example/functional/FunctionalExamples$1StackFrame.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_04_/com/example/functional/FunctionalExamples.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_04_/com/example/functional/FunctionalExamples.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_04_/com/example/functional/FunctionalInterfaceWithDefaultMethod.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_04_/com/example/functional/FunctionalInterfaceWithDefaultMethod.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_04_/com/example/functional/LinkedList$EmptyList.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_04_/com/example/functional/LinkedList$EmptyList.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_04_/com/example/functional/LinkedList.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_04_/com/example/functional/LinkedList.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_04_/com/example/functional/NoArgumentExpression.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_04_/com/example/functional/NoArgumentExpression.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_04_/com/example/functional/NoArgumentExpressionWithException.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_04_/com/example/functional/NoArgumentExpressionWithException.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_04_/com/example/functional/NoValueException.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_04_/com/example/functional/NoValueException.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_04_/com/example/functional/OneArgumentExpression.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_04_/com/example/functional/OneArgumentExpression.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_04_/com/example/functional/OneArgumentExpressionWithException.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_04_/com/example/functional/OneArgumentExpressionWithException.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_04_/com/example/functional/OneArgumentStatement.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_04_/com/example/functional/OneArgumentStatement.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_04_/com/example/functional/OneArgumentStatementWithException.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_04_/com/example/functional/OneArgumentStatementWithException.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_04_/com/example/functional/Option$None.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_04_/com/example/functional/Option$None.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_04_/com/example/functional/Option$Some.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_04_/com/example/functional/Option$Some.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_04_/com/example/functional/Option.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_04_/com/example/functional/Option.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_04_/com/example/functional/Person.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_04_/com/example/functional/Person.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_04_/com/example/functional/SampleFunctionalInterface.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_04_/com/example/functional/SampleFunctionalInterface.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_04_/com/example/functional/ThreeArgumentStatement.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_04_/com/example/functional/ThreeArgumentStatement.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_04_/com/example/functional/Try$Failure.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_04_/com/example/functional/Try$Failure.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_04_/com/example/functional/Try$Success.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_04_/com/example/functional/Try$Success.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_04_/com/example/functional/Try.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_04_/com/example/functional/Try.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_04_/com/example/functional/TwoArgumentExpression.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_04_/com/example/functional/TwoArgumentExpression.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_04_/com/example/functional/TwoArgumentStatement.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_04_/com/example/functional/TwoArgumentStatement.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_04_/module-info.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_04_/module-info.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_05_/com/example/search/ArraySearcher.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_05_/com/example/search/ArraySearcher.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_05_/com/example/search/ArraySorter.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_05_/com/example/search/ArraySorter.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_05_/module-info.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_05_/module-info.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_06_/com/example/sort/ArraySorter.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_06_/com/example/sort/ArraySorter.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_06_/com/example/sort/OrderedPair.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_06_/com/example/sort/OrderedPair.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_06_/module-info.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_06_/module-info.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_07_/com/example/tree/BinaryTree$1StackFame.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_07_/com/example/tree/BinaryTree$1StackFame.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_07_/com/example/tree/BinaryTree$1StackFrame.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_07_/com/example/tree/BinaryTree$1StackFrame.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_07_/com/example/tree/BinaryTree$2StackFame.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_07_/com/example/tree/BinaryTree$2StackFame.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_07_/com/example/tree/BinaryTree$DepthFirstTraversalType.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_07_/com/example/tree/BinaryTree$DepthFirstTraversalType.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_07_/com/example/tree/BinaryTree$Node.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_07_/com/example/tree/BinaryTree$Node.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_07_/com/example/tree/BinaryTree.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_07_/com/example/tree/BinaryTree.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_07_/com/example/tree/FunctionalTree.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_07_/com/example/tree/FunctionalTree.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_07_/com/example/tree/Tree$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_07_/com/example/tree/Tree$1.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_07_/com/example/tree/Tree$Node.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_07_/com/example/tree/Tree$Node.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_07_/com/example/tree/Tree.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_07_/com/example/tree/Tree.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_07_/module-info.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_07_/module-info.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_08_/com/example/searchtree/AVLTree$Node.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_08_/com/example/searchtree/AVLTree$Node.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_08_/com/example/searchtree/AVLTree.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_08_/com/example/searchtree/AVLTree.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_08_/com/example/searchtree/BinarySearchTree.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_08_/com/example/searchtree/BinarySearchTree.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_08_/com/example/searchtree/RedBlackTree$Node.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_08_/com/example/searchtree/RedBlackTree$Node.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_08_/com/example/searchtree/RedBlackTree.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_08_/com/example/searchtree/RedBlackTree.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_08_/module-info.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_08_/module-info.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_09_/com/example/priorityqueue/ArrayHeap$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_09_/com/example/priorityqueue/ArrayHeap$1.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_09_/com/example/priorityqueue/ArrayHeap.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_09_/com/example/priorityqueue/ArrayHeap.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_09_/com/example/priorityqueue/BinomialForest$BinomialTree.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_09_/com/example/priorityqueue/BinomialForest$BinomialTree.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_09_/com/example/priorityqueue/BinomialForest.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_09_/com/example/priorityqueue/BinomialForest.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_09_/com/example/priorityqueue/LinkedHeap$Node.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_09_/com/example/priorityqueue/LinkedHeap$Node.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_09_/com/example/priorityqueue/LinkedHeap.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_09_/com/example/priorityqueue/LinkedHeap.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_09_/com/example/priorityqueue/LinkedList$ListIterator.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_09_/com/example/priorityqueue/LinkedList$ListIterator.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_09_/com/example/priorityqueue/LinkedList$Node.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_09_/com/example/priorityqueue/LinkedList$Node.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_09_/com/example/priorityqueue/LinkedList.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_09_/com/example/priorityqueue/LinkedList.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_09_/com/example/priorityqueue/PriorityQueue.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_09_/com/example/priorityqueue/PriorityQueue.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_09_/com/example/priorityqueue/SortableLinkedList.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_09_/com/example/priorityqueue/SortableLinkedList.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_09_/module-info.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_09_/module-info.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_10_/com/example/graph/AdjacencyListGraphWithDenseVertex$Edge.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_10_/com/example/graph/AdjacencyListGraphWithDenseVertex$Edge.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_10_/com/example/graph/AdjacencyListGraphWithDenseVertex$Vertex.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_10_/com/example/graph/AdjacencyListGraphWithDenseVertex$Vertex.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_10_/com/example/graph/AdjacencyListGraphWithDenseVertex.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_10_/com/example/graph/AdjacencyListGraphWithDenseVertex.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_10_/com/example/graph/AdjacencyListGraphWithSparseVertex$Edge.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_10_/com/example/graph/AdjacencyListGraphWithSparseVertex$Edge.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_10_/com/example/graph/AdjacencyListGraphWithSparseVertex$Vertex.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_10_/com/example/graph/AdjacencyListGraphWithSparseVertex$Vertex.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_10_/com/example/graph/AdjacencyListGraphWithSparseVertex.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_10_/com/example/graph/AdjacencyListGraphWithSparseVertex.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_10_/com/example/graph/AdjacencyMatrixGraphWithDenseVertex$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_10_/com/example/graph/AdjacencyMatrixGraphWithDenseVertex$1.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_10_/com/example/graph/AdjacencyMatrixGraphWithDenseVertex$NullValue.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_10_/com/example/graph/AdjacencyMatrixGraphWithDenseVertex$NullValue.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_10_/com/example/graph/AdjacencyMatrixGraphWithDenseVertex$Vertex.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_10_/com/example/graph/AdjacencyMatrixGraphWithDenseVertex$Vertex.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_10_/com/example/graph/AdjacencyMatrixGraphWithDenseVertex.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_10_/com/example/graph/AdjacencyMatrixGraphWithDenseVertex.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_10_/com/example/graph/AdjacencyMatrixGraphWithSparseVertex$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_10_/com/example/graph/AdjacencyMatrixGraphWithSparseVertex$1.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_10_/com/example/graph/AdjacencyMatrixGraphWithSparseVertex$NullEdgeValue.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_10_/com/example/graph/AdjacencyMatrixGraphWithSparseVertex$NullEdgeValue.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_10_/com/example/graph/AdjacencyMatrixGraphWithSparseVertex.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_10_/com/example/graph/AdjacencyMatrixGraphWithSparseVertex.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_10_/com/example/graph/CycleDetectedException.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_10_/com/example/graph/CycleDetectedException.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_10_/com/example/graph/Graph$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_10_/com/example/graph/Graph$1.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_10_/com/example/graph/Graph$CostEdge.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_10_/com/example/graph/Graph$CostEdge.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_10_/com/example/graph/Graph$Edge.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_10_/com/example/graph/Graph$Edge.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_10_/com/example/graph/Graph$TraversalType.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_10_/com/example/graph/Graph$TraversalType.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_10_/com/example/graph/Graph.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_10_/com/example/graph/Graph.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_10_/com/example/graph/GraphVertex.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_10_/com/example/graph/GraphVertex.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_10_/com/example/graph/UnionFind$Node.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_10_/com/example/graph/UnionFind$Node.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_10_/com/example/graph/UnionFind.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_10_/com/example/graph/UnionFind.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_10_/module-info.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_10_/module-info.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_11_/com/example/reactive/Consumer.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_11_/com/example/reactive/Consumer.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_11_/com/example/reactive/EventConsumer$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_11_/com/example/reactive/EventConsumer$1.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_11_/com/example/reactive/EventConsumer$ConsumerCodeContainer.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_11_/com/example/reactive/EventConsumer$ConsumerCodeContainer.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_11_/com/example/reactive/EventConsumer$StreamEvent.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_11_/com/example/reactive/EventConsumer$StreamEvent.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_11_/com/example/reactive/EventConsumer.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_11_/com/example/reactive/EventConsumer.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_11_/com/example/reactive/EventStream$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_11_/com/example/reactive/EventStream$1.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_11_/com/example/reactive/EventStream$2.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_11_/com/example/reactive/EventStream$2.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_11_/com/example/reactive/EventStream$3.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_11_/com/example/reactive/EventStream$3.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_11_/com/example/reactive/EventStream$4.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_11_/com/example/reactive/EventStream$4.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_11_/com/example/reactive/EventStream.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_11_/com/example/reactive/EventStream.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_11_/com/example/reactive/FileReader.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_11_/com/example/reactive/FileReader.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_11_/com/example/reactive/FilterTask.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_11_/com/example/reactive/FilterTask.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_11_/com/example/reactive/FriendCountProblem.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_11_/com/example/reactive/FriendCountProblem.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_11_/com/example/reactive/MapperTask.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_11_/com/example/reactive/MapperTask.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_11_/com/example/reactive/PerfectNumberTest$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_11_/com/example/reactive/PerfectNumberTest$1.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_11_/com/example/reactive/PerfectNumberTest.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_11_/com/example/reactive/PerfectNumberTest.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_11_/com/example/reactive/ProcessorTask.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_11_/com/example/reactive/ProcessorTask.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_11_/com/example/reactive/ProducerConsumerGarbageFreeQueue$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_11_/com/example/reactive/ProducerConsumerGarbageFreeQueue$1.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_11_/com/example/reactive/ProducerConsumerGarbageFreeQueue$1MutableInteger.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_11_/com/example/reactive/ProducerConsumerGarbageFreeQueue$1MutableInteger.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_11_/com/example/reactive/ProducerConsumerGarbageFreeQueue$Event.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_11_/com/example/reactive/ProducerConsumerGarbageFreeQueue$Event.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_11_/com/example/reactive/ProducerConsumerGarbageFreeQueue$EventType.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_11_/com/example/reactive/ProducerConsumerGarbageFreeQueue$EventType.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_11_/com/example/reactive/ProducerConsumerGarbageFreeQueue.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_11_/com/example/reactive/ProducerConsumerGarbageFreeQueue.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_11_/com/example/reactive/ProducerConsumerQueue$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_11_/com/example/reactive/ProducerConsumerQueue$1.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_11_/com/example/reactive/ProducerConsumerQueue$Event.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_11_/com/example/reactive/ProducerConsumerQueue$Event.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_11_/com/example/reactive/ProducerConsumerQueue$EventType.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_11_/com/example/reactive/ProducerConsumerQueue$EventType.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_11_/com/example/reactive/ProducerConsumerQueue.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_11_/com/example/reactive/ProducerConsumerQueue.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_11_/com/example/reactive/SemaphoreExample.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_11_/com/example/reactive/SemaphoreExample.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_11_/com/example/reactive/Task.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_11_/com/example/reactive/Task.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_11_/com/example/reactive/ThreadSafeCounter.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_11_/com/example/reactive/ThreadSafeCounter.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_11_/com/example/reactive/ThreadSafeFixedLengthBlockingQueue.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_11_/com/example/reactive/ThreadSafeFixedLengthBlockingQueue.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_11_/com/example/reactive/ThreadSafeFixedLengthSpinlockGarbageFreeQueue.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_11_/com/example/reactive/ThreadSafeFixedLengthSpinlockGarbageFreeQueue.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_11_/com/example/reactive/ThreadSafeFixedLengthSpinlockQueue.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_11_/com/example/reactive/ThreadSafeFixedLengthSpinlockQueue.class -------------------------------------------------------------------------------- /mods/com.example.datastructure.chapter_11_/module-info.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-9-Data-Structures-and-Algorithms/e5d743222fd46768a0f0f60554809b47cbe85b0a/mods/com.example.datastructure.chapter_11_/module-info.class -------------------------------------------------------------------------------- /src/com.example.build/com/example/build/Builder.java: -------------------------------------------------------------------------------- 1 | package com.example.build; 2 | import java.io.File; 3 | import java.io.IOException; 4 | import java.util.Stack; 5 | import java.util.LinkedList; 6 | 7 | /** 8 | * Created by debasishc on 5/4/17. 9 | */ 10 | 11 | public class Builder { 12 | public static void main(String [] args) throws Exception{ 13 | LinkedList listOfFiles = new LinkedList<>(); 14 | File baseDirectory = new File(""); 15 | Stack dirStack = new Stack<>(); 16 | dirStack.push(baseDirectory); 17 | System.out.println(baseDirectory.getCanonicalFile()); 18 | while (!dirStack.empty()){ 19 | File currentFile = dirStack.pop().getCanonicalFile(); 20 | if(currentFile.isDirectory()){ 21 | File [] files = currentFile.listFiles(); 22 | for(File f:files){ 23 | dirStack.push(f); 24 | } 25 | }else{ 26 | if(currentFile.toString().endsWith(".java")) { 27 | listOfFiles.add(currentFile.getAbsolutePath()); 28 | } 29 | } 30 | } 31 | listOfFiles.addFirst("src"); 32 | listOfFiles.addFirst("--module-source-path"); 33 | listOfFiles.addFirst("mods"); 34 | listOfFiles.addFirst("-d"); 35 | listOfFiles.addFirst("javac"); 36 | runProcessAndWaitForCompletion(listOfFiles.toArray(new String[0])); 37 | listOfFiles.clear(); 38 | } 39 | 40 | private static void runProcessAndWaitForCompletion(String ... programAndArguments) 41 | throws IOException, InterruptedException { 42 | ProcessBuilder pb = new ProcessBuilder(programAndArguments); 43 | Process process = pb.start(); 44 | process.waitFor(); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/com.example.build/module-info.java: -------------------------------------------------------------------------------- 1 | module com.example.build{ 2 | exports com.example.build; 3 | } 4 | -------------------------------------------------------------------------------- /src/com.example.datastructure.chapter_01_/com/example/datastructure/SimplePowerRemainderComputation.java: -------------------------------------------------------------------------------- 1 | package com.example.datastructure; 2 | 3 | /** 4 | * Created by debasishc on 29/7/16. 5 | */ 6 | public class SimplePowerRemainderComputation { 7 | public static long computeRemainder(long base, long power, long divisor){ 8 | long baseRaisedToPower = 1; 9 | for(long i=1;i<=power;i++){ 10 | baseRaisedToPower *= base; 11 | } 12 | return baseRaisedToPower % divisor; 13 | } 14 | 15 | public static long computeRemainderCorrected(long base, long power, long divisor){ 16 | long baseRaisedToPower = 1; 17 | for(long i=1;i<=power;i++){ 18 | baseRaisedToPower *= base; 19 | baseRaisedToPower %= divisor; 20 | } 21 | return baseRaisedToPower; 22 | } 23 | 24 | public static long computeRemainderUsingEBS(long base, long power, long divisor){ 25 | long baseRaisedToPower = 1; 26 | long powerBitsReversed = 0; 27 | int numBits=0; 28 | while(power>0){ 29 | powerBitsReversed <<= 1; 30 | powerBitsReversed += power & 1; 31 | power >>>= 1; 32 | numBits++; 33 | } 34 | while (numBits-->0){ 35 | if(powerBitsReversed%2==1){ 36 | baseRaisedToPower *= baseRaisedToPower * base; 37 | }else{ 38 | baseRaisedToPower *= baseRaisedToPower; 39 | } 40 | baseRaisedToPower %= divisor; 41 | powerBitsReversed>>>=1; 42 | } 43 | return baseRaisedToPower; 44 | } 45 | public static void main(String [] args){ 46 | System.out.println(computeRemainderUsingEBS(13, 10_000_000, 7)); 47 | 48 | long startTime = System.currentTimeMillis(); 49 | for(int i=0;i<1000;i++){ 50 | computeRemainderCorrected(13, 10_000_000, 7); 51 | } 52 | long endTime = System.currentTimeMillis(); 53 | System.out.println(endTime - startTime); 54 | 55 | startTime = System.currentTimeMillis(); 56 | for(int i=0;i<1000;i++){ 57 | computeRemainderUsingEBS(13, 10_000_000, 7); 58 | } 59 | endTime = System.currentTimeMillis(); 60 | System.out.println(endTime - startTime); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/com.example.datastructure.chapter_01_/module-info.java: -------------------------------------------------------------------------------- 1 | module com.example.datastructure.chapter_01_{ 2 | exports com.example.datastructure; 3 | } 4 | -------------------------------------------------------------------------------- /src/com.example.datastructure.chapter_02_/com/example/datastructure/Array.java: -------------------------------------------------------------------------------- 1 | package com.example.datastructure; 2 | 3 | /** 4 | * Created by debasishc on 4/8/16. 5 | */ 6 | public class Array { 7 | public static void printAllElements(int[] anIntArray){ 8 | for(int i=0;i=targetIndex;i--){ 25 | array[i+1]=array[i]; 26 | } 27 | array[targetIndex]=value; 28 | } 29 | } 30 | 31 | public static int [] insertExtraElementAtIndex(int[] array, int index, int value){ 32 | int [] newArray = new int[array.length+1]; 33 | for(int i=0;i extends LinkedList{ 9 | @Override 10 | public Node appendFirst(E value) { 11 | Node newNode = super.appendFirst(value); 12 | last.next = first; 13 | return newNode; 14 | } 15 | 16 | @Override 17 | public Node appendLast(E value) { 18 | Node newNode = super.appendLast(value); 19 | last.next = first; 20 | return newNode; 21 | } 22 | 23 | @Override 24 | public Node removeFirst() { 25 | Node newNode = super.removeFirst(); 26 | last.next = first; 27 | return newNode; 28 | } 29 | 30 | public void rotate(){ 31 | last = first; 32 | first = first.next; 33 | } 34 | 35 | public static void main(String [] args){ 36 | CircularLinkedList linkedList = new CircularLinkedList<>(); 37 | linkedList.appendFirst(4); 38 | linkedList.appendFirst(1); 39 | linkedList.appendFirst(2); 40 | linkedList.appendFirst(3); 41 | linkedList.appendLast(8); 42 | linkedList.appendLast(7); 43 | linkedList.appendLast(18); 44 | 45 | Iterator iterator = linkedList.iterator(); 46 | for(int i=0;i<30;i++){ 47 | System.out.print(" "+ iterator.next()); 48 | } 49 | 50 | System.out.println(); 51 | 52 | for(int i=0;i<30;i++){ 53 | System.out.print(" "+ linkedList.first); 54 | linkedList.rotate(); 55 | } 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /src/com.example.datastructure.chapter_02_/com/example/datastructure/DecimalInteger.java: -------------------------------------------------------------------------------- 1 | package com.example.datastructure; 2 | 3 | /** 4 | * Created by debasish on 24/7/16. 5 | */ 6 | public class DecimalInteger implements Cloneable { 7 | char[] digits; 8 | Character optionalCarryDigit; 9 | int shift; 10 | 11 | protected DecimalInteger() { 12 | 13 | } 14 | 15 | public DecimalInteger(String value) { 16 | digits = value.toCharArray(); 17 | //Check whether digits are okay 18 | for (char digit : digits) { 19 | if (digit > '9' || digit < '0') { 20 | throw new NumberFormatException("Illegal character '" + digit + "'"); 21 | } 22 | } 23 | } 24 | 25 | public DecimalInteger(DecimalInteger source) { 26 | if (source.optionalCarryDigit != null) { 27 | digits = new char[source.digits.length + 1]; 28 | digits[0] = source.optionalCarryDigit; 29 | System.arraycopy(source.digits, 0, digits, 1, source.digits.length); 30 | } else { 31 | digits = source.digits; 32 | } 33 | shift = source.shift; 34 | } 35 | 36 | @Override 37 | public DecimalInteger clone() { 38 | return new DecimalInteger(this); 39 | } 40 | 41 | public String toString() { 42 | StringBuilder sb = new StringBuilder(); 43 | if (optionalCarryDigit == null) { 44 | sb.append(digits); 45 | } else { 46 | sb.append(clone().toString()); 47 | } 48 | for (int i = 0; i < shift; i++) { 49 | sb.append('0'); 50 | } 51 | return sb.toString(); 52 | } 53 | 54 | public DecimalInteger add(DecimalInteger rhs) { 55 | int resultShift = Math.min(shift, rhs.shift); 56 | int minResultDigs = Math.max(digits.length + shift, rhs.digits.length + rhs.shift) 57 | - resultShift; 58 | 59 | if (optionalCarryDigit != null || rhs.optionalCarryDigit != null) { 60 | minResultDigs++; 61 | } 62 | 63 | char[] resultDigs = new char[minResultDigs]; 64 | int currentCarry = 0; 65 | int lhsPos = digits.length - 1 + shift - resultShift; 66 | int rhsPos = rhs.digits.length - 1 + rhs.shift - resultShift; 67 | for (int resultPos = minResultDigs - 1; resultPos >= 0; resultPos--) { 68 | int resultValueForDig = 0; 69 | if (lhsPos < digits.length && lhsPos >= 0) 70 | resultValueForDig += (digits[lhsPos] - '0'); 71 | else if (lhsPos == -1 && optionalCarryDigit != null) { 72 | resultValueForDig += 1; 73 | } 74 | 75 | if (rhsPos < rhs.digits.length && rhsPos >= 0) 76 | resultValueForDig += (rhs.digits[rhsPos] - '0'); 77 | else if (rhsPos == -1 && rhs.optionalCarryDigit != null) { 78 | resultValueForDig += 1; 79 | } 80 | resultValueForDig += currentCarry; 81 | if (resultValueForDig <= 9) { 82 | resultDigs[resultPos] = (char) (resultValueForDig + '0'); 83 | currentCarry = 0; 84 | } else { 85 | resultDigs[resultPos] = (char) (resultValueForDig - 10 + '0'); 86 | currentCarry = 1; 87 | } 88 | lhsPos--; 89 | rhsPos--; 90 | } 91 | DecimalInteger result = new DecimalInteger(); 92 | result.digits = resultDigs; 93 | if (currentCarry > 0) { 94 | result.optionalCarryDigit = (char) (currentCarry + '0'); 95 | } 96 | result.shift = resultShift; 97 | 98 | return result; 99 | 100 | } 101 | 102 | protected DecimalInteger shiftBy(int places){ 103 | DecimalInteger newOne = clone(); 104 | newOne.shift+=places; 105 | return newOne; 106 | } 107 | 108 | protected DecimalInteger multiplyByADigit(char digit) { 109 | int minResultDigs = digits.length; 110 | if (optionalCarryDigit != null) { 111 | minResultDigs++; 112 | } 113 | char[] resultDigs = new char[minResultDigs]; 114 | int currentCarry = 0; 115 | int multiplier = digit - '0'; 116 | int thisPosition = digits.length - 1; 117 | for (int i = minResultDigs - 1; i >= 0; i--) { 118 | int resultDig = currentCarry; 119 | if (thisPosition >= 0) 120 | resultDig += (digits[thisPosition] - '0') * multiplier; 121 | currentCarry = resultDig / 10; 122 | resultDig = resultDig % 10; 123 | resultDigs[i] = (char) (resultDig + '0'); 124 | thisPosition--; 125 | } 126 | DecimalInteger decimalInteger = new DecimalInteger(); 127 | if (currentCarry > 0) { 128 | decimalInteger.optionalCarryDigit = (char) (currentCarry + '0'); 129 | } 130 | decimalInteger.digits = resultDigs; 131 | decimalInteger.shift = shift; 132 | return decimalInteger; 133 | } 134 | 135 | public DecimalInteger multiply(DecimalInteger rhs){ 136 | DecimalInteger currentSum = new DecimalInteger("0"); 137 | int resultShift = rhs.shift; 138 | if(rhs.optionalCarryDigit!=null){ 139 | currentSum = multiplyByADigit(rhs.optionalCarryDigit).shiftBy(rhs.digits.length); 140 | } 141 | for(int i=rhs.digits.length -1 ;i>=0;i--){ 142 | currentSum = currentSum.add(multiplyByADigit(rhs.digits[i]).shiftBy(rhs.digits.length -1 - i)); 143 | } 144 | return currentSum.shiftBy(resultShift); 145 | 146 | } 147 | 148 | public static void main(String[] args) { 149 | DecimalInteger lhs = new DecimalInteger("20394"); 150 | lhs.shift = 1; 151 | System.out.println(lhs); 152 | DecimalInteger rhs = new DecimalInteger("999999"); 153 | rhs.shift = 3; 154 | DecimalInteger third = new DecimalInteger("979"); 155 | third.shift = 1; 156 | System.out.println(lhs.add(rhs)); 157 | System.out.println(lhs.add(rhs).add(third)); 158 | System.out.println(lhs.multiplyByADigit('5')); 159 | System.out.println(lhs.multiply(third)); 160 | } 161 | } 162 | -------------------------------------------------------------------------------- /src/com.example.datastructure.chapter_02_/com/example/datastructure/DoublyLinkedList.java: -------------------------------------------------------------------------------- 1 | package com.example.datastructure; 2 | 3 | import java.util.Iterator; 4 | import java.util.NoSuchElementException; 5 | 6 | /** 7 | * Created by debasishc on 21/7/16. 8 | */ 9 | public class DoublyLinkedList extends LinkedList { 10 | 11 | public static class DoublyLinkedNode extends Node { 12 | protected DoublyLinkedNode prev; 13 | } 14 | 15 | 16 | @Override 17 | protected Node getNewNode() { 18 | return new DoublyLinkedNode<>(); 19 | } 20 | 21 | @Override 22 | public Node appendFirst(E value) { 23 | Node node = super.appendFirst(value); 24 | if (first.next != null) 25 | ((DoublyLinkedNode) first.next).prev = (DoublyLinkedNode) first; 26 | return node; 27 | } 28 | 29 | @Override 30 | public Node insert(int index, E value) { 31 | DoublyLinkedNode inserted = (DoublyLinkedNode) super.insert(index, value); 32 | if(index!=0 && index!=length) { 33 | if (inserted.next != null) { 34 | inserted.prev = ((DoublyLinkedNode) inserted.next).prev; 35 | ((DoublyLinkedNode) inserted.next).prev = inserted; 36 | } 37 | } 38 | return inserted; 39 | } 40 | 41 | @Override 42 | public Node appendLast(E value) { 43 | DoublyLinkedNode origLast = (DoublyLinkedNode) this.last; 44 | Node node = super.appendLast(value); 45 | ((DoublyLinkedNode) this.last).prev = origLast; 46 | return node; 47 | } 48 | 49 | @Override 50 | public Node removeAtIndex(int index) { 51 | if(index<0||index>=length){ 52 | throw new NoSuchElementException("index = "+index); 53 | } 54 | if(index==length-1){ 55 | return removeLast(); 56 | } 57 | DoublyLinkedNode nodeRemoved = (DoublyLinkedNode) super.removeAtIndex(index); 58 | if ((DoublyLinkedNode) nodeRemoved.next != null) 59 | ((DoublyLinkedNode) nodeRemoved.next).prev = nodeRemoved.prev; 60 | 61 | return nodeRemoved; 62 | } 63 | 64 | 65 | @Override 66 | public Node removeFirst() { 67 | super.removeFirst(); 68 | if (first != null) { 69 | ((DoublyLinkedNode) first).prev = null; 70 | } 71 | return first; 72 | } 73 | 74 | public void removeNode(DoublyLinkedNode node){ 75 | if(node==last){ 76 | removeLast(); 77 | }else if(node==first){ 78 | removeFirst(); 79 | }else{ 80 | node.prev.next = node.next; 81 | length--; 82 | } 83 | } 84 | 85 | @Override 86 | public Node removeLast() { 87 | Node origLast = last; 88 | if(last==null){ 89 | throw new IllegalStateException("Removing element from an empty list"); 90 | } 91 | 92 | last = ((DoublyLinkedNode)last).prev; 93 | if(last!=null){ 94 | last.next = null; 95 | }else{ 96 | first = null; 97 | } 98 | length--; 99 | return origLast; 100 | } 101 | 102 | protected class ReverseListIterator extends ListIterator{ 103 | public ReverseListIterator(){ 104 | nextNode = last; 105 | } 106 | 107 | @Override 108 | public E next() { 109 | if(nextNode == null) 110 | throw new IllegalStateException(); 111 | DoublyLinkedNode nodeToReturn = (DoublyLinkedNode) nextNode; 112 | nextNode = nodeToReturn.prev; 113 | return nodeToReturn.value; 114 | } 115 | } 116 | 117 | public Iterator reverseIterator(){ 118 | return new ReverseListIterator(); 119 | } 120 | 121 | public static void main(String [] args){ 122 | DoublyLinkedList doublyLinkedList = new DoublyLinkedList<>(); 123 | doublyLinkedList.appendFirst(4); 124 | doublyLinkedList.appendFirst(1); 125 | doublyLinkedList.appendFirst(2); 126 | doublyLinkedList.appendFirst(3); 127 | doublyLinkedList.appendLast(8); 128 | doublyLinkedList.appendLast(7); 129 | doublyLinkedList.appendLast(18); 130 | doublyLinkedList.appendFirst(3); 131 | doublyLinkedList.appendLast(8); 132 | doublyLinkedList.appendLast(7); 133 | doublyLinkedList.appendLast(18); 134 | doublyLinkedList.insert(2, 51); 135 | doublyLinkedList.insert(0, 510); 136 | 137 | while (doublyLinkedList.getLength()>0){ 138 | doublyLinkedList.removeLast(); 139 | } 140 | 141 | 142 | Iterator reverseIterator = doublyLinkedList.reverseIterator(); 143 | while(reverseIterator.hasNext()){ 144 | System.out.println(reverseIterator.next()); 145 | } 146 | 147 | 148 | } 149 | } 150 | 151 | -------------------------------------------------------------------------------- /src/com.example.datastructure.chapter_02_/com/example/datastructure/OrderedPair.java: -------------------------------------------------------------------------------- 1 | package com.example.datastructure; 2 | 3 | /** 4 | * Created by debasishc on 4/10/16. 5 | */ 6 | public class OrderedPair { 7 | public E _1; 8 | public F _2; 9 | 10 | public OrderedPair(E _1, F _2) { 11 | this._1 = _1; 12 | this._2 = _2; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/com.example.datastructure.chapter_02_/module-info.java: -------------------------------------------------------------------------------- 1 | module com.example.datastructure.chapter_02_{ 2 | exports com.example.datastructure; 3 | } 4 | -------------------------------------------------------------------------------- /src/com.example.datastructure.chapter_03_/com/example/adt/DoubleEndedQueue.java: -------------------------------------------------------------------------------- 1 | package com.example.adt; 2 | 3 | /** 4 | * Created by debasishc on 12/8/16. 5 | */ 6 | public interface DoubleEndedQueue extends Stack { 7 | void inject(E value); 8 | E eject(); 9 | E peekLast(); 10 | } 11 | -------------------------------------------------------------------------------- /src/com.example.datastructure.chapter_03_/com/example/adt/DoubleEndedQueueImplArray.java: -------------------------------------------------------------------------------- 1 | package com.example.adt; 2 | 3 | import java.util.Iterator; 4 | 5 | /** 6 | * Created by debasishc on 12/8/16. 7 | */ 8 | public class DoubleEndedQueueImplArray extends QueueImplArray implements DoubleEndedQueue { 9 | 10 | public DoubleEndedQueueImplArray(int size) { 11 | super(size); 12 | } 13 | 14 | @Override 15 | public void inject(E value) { 16 | enqueue(value); 17 | } 18 | 19 | @Override 20 | public E eject() { 21 | if (length <= 0) { 22 | return null; 23 | } 24 | end = (end + array.length - 1) % array.length; 25 | E value = array[end]; 26 | length--; 27 | return value; 28 | } 29 | 30 | @Override 31 | public E peekLast() { 32 | if (length <= 0) { 33 | return null; 34 | } 35 | return array[(end + array.length - 1) % array.length]; 36 | } 37 | 38 | @Override 39 | public void push(E value) { 40 | if (length >= array.length) { 41 | throw new NoSpaceException("No more space to add an element"); 42 | } 43 | start = (start + array.length - 1) % array.length; 44 | array[start] = value; 45 | length++; 46 | } 47 | 48 | @Override 49 | public E pop() { 50 | return dequeue(); 51 | } 52 | 53 | public static void main(String [] args){ 54 | DoubleEndedQueue store = new DoubleEndedQueueImplArray<>(4); 55 | store.push(4); 56 | store.push(3); 57 | store.push(2); 58 | System.out.println(store.pop()); 59 | System.out.println(store.pop()); 60 | System.out.println(store.pop()); 61 | System.out.println(store.pop()); 62 | store.inject(4); 63 | store.inject(3); 64 | store.inject(2); 65 | System.out.println(store.eject()); 66 | System.out.println(store.eject()); 67 | System.out.println(store.eject()); 68 | System.out.println(store.eject()); 69 | store.inject(4); 70 | store.inject(3); 71 | store.inject(2); 72 | System.out.println(store.eject()); 73 | System.out.println(store.eject()); 74 | System.out.println(store.eject()); 75 | System.out.println(store.eject()); 76 | 77 | store.push(4); 78 | store.push(3); 79 | store.push(2); 80 | System.out.println(store.eject()); 81 | System.out.println(store.eject()); 82 | System.out.println(store.eject()); 83 | System.out.println(store.eject()); 84 | 85 | store.inject(4); 86 | store.inject(3); 87 | store.inject(2); 88 | System.out.println(store.pop()); 89 | System.out.println(store.pop()); 90 | System.out.println(store.pop()); 91 | System.out.println(store.pop()); 92 | 93 | 94 | } 95 | 96 | @Override 97 | public E checkFirst() { 98 | return peek(); 99 | } 100 | 101 | @Override 102 | public void insert(E value) { 103 | enqueue(value); 104 | } 105 | 106 | @Override 107 | public E pickFirst() { 108 | return dequeue(); 109 | } 110 | 111 | @Override 112 | public Iterator iterator() { 113 | return null; 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /src/com.example.datastructure.chapter_03_/com/example/adt/DoubleEndedQueueImplLinkedList.java: -------------------------------------------------------------------------------- 1 | package com.example.adt; 2 | 3 | import com.example.datastructure.DoublyLinkedList; 4 | import com.example.datastructure.LinkedList; 5 | 6 | /** 7 | * Created by debasishc on 12/8/16. 8 | */ 9 | public class DoubleEndedQueueImplLinkedList extends StackImplLinkedList implements DoubleEndedQueue { 10 | 11 | @Override 12 | protected LinkedList getNewLinkedList() { 13 | return new DoublyLinkedList(); 14 | } 15 | 16 | @Override 17 | public void inject(E value) { 18 | list.appendLast(value); 19 | } 20 | 21 | @Override 22 | public E eject() { 23 | if(list.getLength()==0){ 24 | return null; 25 | } 26 | E value = list.getLast(); 27 | list.removeLast(); 28 | return value; 29 | } 30 | 31 | @Override 32 | public E peekLast() { 33 | if(list.getLength()==0){ 34 | return null; 35 | } 36 | return list.getLast(); 37 | } 38 | 39 | public static void main(String [] args){ 40 | DoubleEndedQueue store = new DoubleEndedQueueImplLinkedList<>(); 41 | store.push(4); 42 | store.push(3); 43 | store.push(2); 44 | System.out.println(store.pop()); 45 | System.out.println(store.pop()); 46 | System.out.println(store.pop()); 47 | System.out.println(store.pop()); 48 | store.inject(4); 49 | store.inject(3); 50 | store.inject(2); 51 | System.out.println(store.eject()); 52 | System.out.println(store.eject()); 53 | System.out.println(store.eject()); 54 | System.out.println(store.eject()); 55 | store.inject(4); 56 | store.inject(3); 57 | store.inject(2); 58 | System.out.println(store.eject()); 59 | System.out.println(store.eject()); 60 | System.out.println(store.eject()); 61 | System.out.println(store.eject()); 62 | 63 | store.push(4); 64 | store.push(3); 65 | store.push(2); 66 | System.out.println(store.eject()); 67 | System.out.println(store.eject()); 68 | System.out.println(store.eject()); 69 | System.out.println(store.eject()); 70 | 71 | store.inject(4); 72 | store.inject(3); 73 | store.inject(2); 74 | System.out.println(store.pop()); 75 | System.out.println(store.pop()); 76 | System.out.println(store.pop()); 77 | System.out.println(store.pop()); 78 | 79 | 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /src/com.example.datastructure.chapter_03_/com/example/adt/NoSpaceException.java: -------------------------------------------------------------------------------- 1 | package com.example.adt; 2 | 3 | /** 4 | * Created by debasishc on 12/8/16. 5 | */ 6 | public class NoSpaceException extends RuntimeException{ 7 | public NoSpaceException(String message) { 8 | super(message); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/com.example.datastructure.chapter_03_/com/example/adt/OrderedStore.java: -------------------------------------------------------------------------------- 1 | package com.example.adt; 2 | 3 | /** 4 | * Created by debasishc on 22/12/16. 5 | */ 6 | public interface OrderedStore extends Iterable{ 7 | void insert(E value); 8 | E pickFirst(); 9 | E checkFirst(); 10 | } 11 | -------------------------------------------------------------------------------- /src/com.example.datastructure.chapter_03_/com/example/adt/Queue.java: -------------------------------------------------------------------------------- 1 | package com.example.adt; 2 | 3 | /** 4 | * Created by debasishc on 12/8/16. 5 | */ 6 | public interface Queue extends OrderedStore{ 7 | void enqueue(E value); 8 | E dequeue(); 9 | E peek(); 10 | 11 | @Override 12 | default E checkFirst(){ 13 | return peek(); 14 | } 15 | 16 | @Override 17 | default void insert(E value){ 18 | enqueue(value); 19 | } 20 | 21 | @Override 22 | default E pickFirst(){ 23 | return dequeue(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/com.example.datastructure.chapter_03_/com/example/adt/QueueImplArray.java: -------------------------------------------------------------------------------- 1 | package com.example.adt; 2 | 3 | import java.util.Iterator; 4 | import java.util.NoSuchElementException; 5 | 6 | /** 7 | * Created by debasishc on 12/8/16. 8 | */ 9 | public class QueueImplArray implements Queue{ 10 | protected E[] array; 11 | protected int start=0; 12 | protected int end=0; 13 | protected int length=0; 14 | public QueueImplArray(int size){ 15 | array = (E[]) new Object[size]; 16 | } 17 | 18 | @Override 19 | public void enqueue(E value) { 20 | if(length>=array.length){ 21 | throw new NoSpaceException("No more space to add an element"); 22 | } 23 | array[end] = value; 24 | end = (end+1) % array.length; 25 | length++; 26 | 27 | } 28 | 29 | @Override 30 | public E dequeue() { 31 | if(length<=0){ 32 | return null; 33 | } 34 | E value = array[start]; 35 | start = (start+1) % array.length; 36 | length--; 37 | return value; 38 | } 39 | 40 | @Override 41 | public E peek() { 42 | if(length<=0){ 43 | return null; 44 | } 45 | return array[start]; 46 | } 47 | 48 | public static void main(String [] args){ 49 | Queue store = new QueueImplArray<>(4); 50 | store.enqueue(4); 51 | store.enqueue(3); 52 | store.enqueue(2); 53 | System.out.println(store.dequeue()); 54 | System.out.println(store.dequeue()); 55 | System.out.println(store.dequeue()); 56 | System.out.println(store.dequeue()); 57 | store.enqueue(4); 58 | store.enqueue(3); 59 | store.enqueue(2); 60 | System.out.println(store.dequeue()); 61 | System.out.println(store.dequeue()); 62 | System.out.println(store.dequeue()); 63 | System.out.println(store.dequeue()); 64 | store.enqueue(4); 65 | store.enqueue(3); 66 | store.enqueue(2); 67 | System.out.println(store.dequeue()); 68 | System.out.println(store.dequeue()); 69 | System.out.println(store.dequeue()); 70 | System.out.println(store.dequeue()); 71 | 72 | } 73 | 74 | @Override 75 | public Iterator iterator() { 76 | return new Iterator() { 77 | int nextPosition = start; 78 | @Override 79 | public boolean hasNext() { 80 | if(length==0){ 81 | return false; 82 | } 83 | if(start= start && 85 | nextPosition < end; 86 | }else{ 87 | return nextPosition>start || nextPosition<=end; 88 | } 89 | } 90 | 91 | @Override 92 | public E next() { 93 | int pos = nextPosition; 94 | nextPosition = (nextPosition + 1) % array.length; 95 | return array[pos]; 96 | } 97 | }; 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /src/com.example.datastructure.chapter_03_/com/example/adt/QueueImplLinkedList.java: -------------------------------------------------------------------------------- 1 | package com.example.adt; 2 | 3 | import com.example.datastructure.LinkedList; 4 | 5 | import java.util.Iterator; 6 | 7 | /** 8 | * Created by debasishc on 12/8/16. 9 | */ 10 | public class QueueImplLinkedList implements Queue{ 11 | protected LinkedList list = getNewLinkedList(); 12 | 13 | protected LinkedList getNewLinkedList(){ 14 | return new LinkedList<>(); 15 | } 16 | 17 | @Override 18 | public void enqueue(E value) { 19 | list.appendLast(value); 20 | } 21 | 22 | @Override 23 | public E dequeue() { 24 | if(list.getLength()==0){ 25 | return null; 26 | } 27 | E value = list.getFirst(); 28 | list.removeFirst(); 29 | return value; 30 | } 31 | 32 | @Override 33 | public E peek() { 34 | if(list.getLength()==0){ 35 | return null; 36 | } 37 | return list.getFirst(); 38 | } 39 | 40 | public static void main(String [] args){ 41 | Queue store = new QueueImplLinkedList<>(); 42 | store.enqueue(4); 43 | store.enqueue(3); 44 | store.enqueue(2); 45 | System.out.println(store.dequeue()); 46 | System.out.println(store.dequeue()); 47 | System.out.println(store.dequeue()); 48 | System.out.println(store.dequeue()); 49 | store.enqueue(4); 50 | store.enqueue(3); 51 | store.enqueue(2); 52 | System.out.println(store.dequeue()); 53 | System.out.println(store.dequeue()); 54 | System.out.println(store.dequeue()); 55 | System.out.println(store.dequeue()); 56 | store.enqueue(4); 57 | store.enqueue(3); 58 | store.enqueue(2); 59 | System.out.println(store.dequeue()); 60 | System.out.println(store.dequeue()); 61 | System.out.println(store.dequeue()); 62 | System.out.println(store.dequeue()); 63 | 64 | } 65 | 66 | @Override 67 | public Iterator iterator() { 68 | return list.iterator(); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/com.example.datastructure.chapter_03_/com/example/adt/Stack.java: -------------------------------------------------------------------------------- 1 | package com.example.adt; 2 | 3 | /** 4 | * Created by debasishc on 12/8/16. 5 | */ 6 | public interface Stack extends OrderedStore{ 7 | void push(E value); 8 | E pop(); 9 | E peek(); 10 | @Override 11 | default E checkFirst(){ 12 | return peek(); 13 | } 14 | 15 | @Override 16 | default void insert(E value){ 17 | push(value); 18 | } 19 | 20 | @Override 21 | default E pickFirst(){ 22 | return pop(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/com.example.datastructure.chapter_03_/com/example/adt/StackImplArray.java: -------------------------------------------------------------------------------- 1 | package com.example.adt; 2 | 3 | import java.util.Iterator; 4 | import java.util.NoSuchElementException; 5 | 6 | /** 7 | * Created by debasishc on 12/8/16. 8 | */ 9 | public class StackImplArray implements Stack { 10 | protected E[] array; 11 | int top=-1; 12 | 13 | public StackImplArray(int size){ 14 | array = (E[])new Object[size]; 15 | } 16 | @Override 17 | public void push(E value) { 18 | if(top == array.length-1){ 19 | throw new NoSpaceException("No more space in stack"); 20 | } 21 | top++; 22 | array[top] = value; 23 | } 24 | 25 | @Override 26 | public E pop() { 27 | if(top==-1){ 28 | return null; 29 | } 30 | top--; 31 | return array[top+1]; 32 | } 33 | 34 | @Override 35 | public E peek() { 36 | if(top==-1){ 37 | return null; 38 | } 39 | return array[top]; 40 | } 41 | 42 | public static void main(String [] args){ 43 | Stack store = new StackImplArray<>(4); 44 | store.push(4); 45 | store.push(3); 46 | store.push(2); 47 | System.out.println(store.pop()); 48 | System.out.println(store.pop()); 49 | System.out.println(store.pop()); 50 | System.out.println(store.pop()); 51 | 52 | } 53 | 54 | @Override 55 | public Iterator iterator() { 56 | return new Iterator() { 57 | int nextPosition = 0; 58 | @Override 59 | public boolean hasNext() { 60 | return nextPosition<=top; 61 | } 62 | 63 | @Override 64 | public E next() { 65 | return array[nextPosition++]; 66 | } 67 | }; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/com.example.datastructure.chapter_03_/com/example/adt/StackImplLinkedList.java: -------------------------------------------------------------------------------- 1 | package com.example.adt; 2 | 3 | import com.example.datastructure.LinkedList; 4 | 5 | import java.util.Iterator; 6 | 7 | /** 8 | * Created by debasishc on 12/8/16. 9 | */ 10 | public class StackImplLinkedList implements Stack { 11 | protected LinkedList list = getNewLinkedList(); 12 | 13 | protected LinkedList getNewLinkedList(){ 14 | return new LinkedList<>(); 15 | } 16 | 17 | @Override 18 | public void push(E value) { 19 | list.appendFirst(value); 20 | } 21 | 22 | @Override 23 | public E pop() { 24 | if(list.getLength()==0){ 25 | return null; 26 | } 27 | E value = list.getFirst(); 28 | list.removeFirst(); 29 | return value; 30 | } 31 | 32 | @Override 33 | public E peek() { 34 | if(list.getLength()==0){ 35 | return null; 36 | } 37 | return list.getFirst(); 38 | } 39 | 40 | public static void main(String [] args){ 41 | Stack store = new StackImplLinkedList<>(); 42 | store.push(4); 43 | store.push(3); 44 | store.push(2); 45 | System.out.println(store.pop()); 46 | System.out.println(store.pop()); 47 | System.out.println(store.pop()); 48 | System.out.println(store.pop()); 49 | 50 | } 51 | 52 | @Override 53 | public Iterator iterator() { 54 | return list.iterator(); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/com.example.datastructure.chapter_03_/module-info.java: -------------------------------------------------------------------------------- 1 | module com.example.datastructure.chapter_03_{ 2 | exports com.example.adt; 3 | requires com.example.datastructure.chapter_02_; 4 | } 5 | -------------------------------------------------------------------------------- /src/com.example.datastructure.chapter_04_/com/example/functional/Address.java: -------------------------------------------------------------------------------- 1 | package com.example.functional; 2 | 3 | /** 4 | * Created by debasishc on 4/9/16. 5 | */ 6 | public class Address { 7 | private String street; 8 | private City city; 9 | 10 | public Address(City city, String street) { 11 | this.city = city; 12 | this.street = street; 13 | } 14 | 15 | public Option getCity() { 16 | return Option.optionOf(city); 17 | } 18 | 19 | public Option getStreet() { 20 | return Option.optionOf(street); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/com.example.datastructure.chapter_04_/com/example/functional/BinomialForest.java: -------------------------------------------------------------------------------- 1 | package com.example.functional; 2 | 3 | /** 4 | * Created by debasishc on 17/11/16. 5 | */ 6 | public class BinomialForest { 7 | public static class BinomialTree{ 8 | BinomialTree merge(BinomialTree rhs){return null;} 9 | } 10 | public static class CombinationBinomialTree extends BinomialTree{ 11 | protected BinomialTree topTree; 12 | protected BinomialTree subordinateTree; 13 | int height; 14 | 15 | @Override 16 | public BinomialTree merge( 17 | BinomialTree rhs) { 18 | return null; 19 | } 20 | 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/com.example.datastructure.chapter_04_/com/example/functional/City.java: -------------------------------------------------------------------------------- 1 | package com.example.functional; 2 | 3 | /** 4 | * Created by debasishc on 4/9/16. 5 | */ 6 | public class City { 7 | private String name; 8 | private Country country; 9 | 10 | public City(Country country, String name) { 11 | this.country = country; 12 | this.name = name; 13 | } 14 | 15 | public Option getCountry() { 16 | return Option.optionOf(country); 17 | } 18 | 19 | public Option getName() { 20 | return Option.optionOf(name); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /src/com.example.datastructure.chapter_04_/com/example/functional/Country.java: -------------------------------------------------------------------------------- 1 | package com.example.functional; 2 | 3 | /** 4 | * Created by debasishc on 4/9/16. 5 | */ 6 | public class Country { 7 | private String name; 8 | private String countryCode; 9 | 10 | 11 | public Country(String countryCode, String name) { 12 | this.countryCode = countryCode; 13 | this.name = name; 14 | } 15 | 16 | public Option getCountryCode() { 17 | return Option.optionOf(countryCode); 18 | } 19 | 20 | public Option getName() { 21 | return Option.optionOf(name); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/com.example.datastructure.chapter_04_/com/example/functional/FunctionalInterfaceWithDefaultMethod.java: -------------------------------------------------------------------------------- 1 | package com.example.functional; 2 | 3 | /** 4 | * Created by debasishc on 16/2/17. 5 | */ 6 | @FunctionalInterface 7 | public interface FunctionalInterfaceWithDefaultMethod { 8 | int modify(int x); 9 | default int modifyTwice(int x){return modify(modify(x));} 10 | } 11 | -------------------------------------------------------------------------------- /src/com.example.datastructure.chapter_04_/com/example/functional/LinkedList.java: -------------------------------------------------------------------------------- 1 | package com.example.functional; 2 | 3 | /** 4 | * Created by debasishc on 28/8/16. 5 | */ 6 | public class LinkedList { 7 | private E head; 8 | private LinkedList tail; 9 | private int length; 10 | 11 | protected LinkedList(){ 12 | 13 | } 14 | 15 | protected LinkedList(E head, LinkedList tail){ 16 | this.head = head; 17 | this.tail = tail; 18 | this.length = tail.getLength()+1; 19 | } 20 | 21 | public static class EmptyList extends LinkedList{ 22 | @Override 23 | public E head() { 24 | throw new NoValueException("head() invoked on empty list"); 25 | } 26 | 27 | @Override 28 | public LinkedList tail() { 29 | throw new NoValueException("tail() invoked on empty list"); 30 | } 31 | 32 | @Override 33 | public void forEach(OneArgumentStatement processor) {} 34 | 35 | @Override 36 | public LinkedList map(OneArgumentExpression transformer) { 37 | return LinkedList.emptyList(); 38 | } 39 | 40 | @Override 41 | public R foldLeft(R initialValue, TwoArgumentExpression computer) { 42 | return initialValue; 43 | } 44 | 45 | @Override 46 | public R foldRight(TwoArgumentExpression computer, R initialValue) { 47 | return initialValue; 48 | } 49 | 50 | @Override 51 | public LinkedList filter(OneArgumentExpression selector) { 52 | return this; 53 | } 54 | 55 | @Override 56 | public LinkedList flatMap(OneArgumentExpression> transformer) { 57 | return LinkedList.emptyList(); 58 | } 59 | 60 | @Override 61 | public boolean isEmpty() { 62 | return true; 63 | } 64 | 65 | @Override 66 | public int getLength() { 67 | return 0; 68 | } 69 | } 70 | 71 | public static LinkedList emptyList(){ 72 | return new EmptyList<>(); 73 | } 74 | public E head(){ 75 | return head; 76 | } 77 | public LinkedList tail(){ 78 | return tail; 79 | } 80 | public LinkedList add(E value){ 81 | return new LinkedList<>(value,this); 82 | } 83 | public void forEach(OneArgumentStatement processor){ 84 | processor.doSomething(head()); 85 | tail().forEach(processor); 86 | } 87 | 88 | public LinkedList map(OneArgumentExpression transformer){ 89 | return new LinkedList<>(transformer.compute(head()), tail.map(transformer)); 90 | } 91 | 92 | public LinkedList append(LinkedList rhs){ 93 | return this.foldRight((x,l)->l.add(x),rhs); 94 | } 95 | 96 | public LinkedList flatMap(OneArgumentExpression> transformer){ 97 | return transformer.compute(head()).append(tail().flatMap(transformer)); 98 | } 99 | 100 | public R foldLeft(R initialValue, TwoArgumentExpression computer){ 101 | R newInitialValue = computer.compute(initialValue, head()); 102 | return tail().foldLeft(newInitialValue, computer); 103 | } 104 | 105 | public R foldRight(TwoArgumentExpression computer, R initialValue){ 106 | R computedValue = tail().foldRight(computer, initialValue); 107 | return computer.compute(head(), computedValue); 108 | } 109 | 110 | public LinkedList filter(OneArgumentExpression selector){ 111 | if(selector.compute(head())){ 112 | return new LinkedList(head(), tail().filter(selector)); 113 | }else{ 114 | return tail().filter(selector); 115 | } 116 | } 117 | public boolean isEmpty(){ 118 | return false; 119 | } 120 | 121 | private static LinkedList ofRange(int start, int end, LinkedList tailList){ 122 | if(start>=end){ 123 | return tailList; 124 | }else{ 125 | return ofRange(start+1, end, tailList).add(start); 126 | } 127 | } 128 | 129 | public static LinkedList ofRange(int start, int end){ 130 | return ofRange(start,end, LinkedList.emptyList()); 131 | } 132 | 133 | public int getLength(){ 134 | return length; 135 | } 136 | } 137 | -------------------------------------------------------------------------------- /src/com.example.datastructure.chapter_04_/com/example/functional/NoArgumentExpression.java: -------------------------------------------------------------------------------- 1 | package com.example.functional; 2 | 3 | /** 4 | * Created by debasishc on 22/1/17. 5 | */ 6 | @FunctionalInterface 7 | public interface NoArgumentExpression { 8 | E value(); 9 | } 10 | -------------------------------------------------------------------------------- /src/com.example.datastructure.chapter_04_/com/example/functional/NoArgumentExpressionWithException.java: -------------------------------------------------------------------------------- 1 | package com.example.functional; 2 | 3 | /** 4 | * Created by debasishc on 8/9/16. 5 | */ 6 | @FunctionalInterface 7 | public interface NoArgumentExpressionWithException { 8 | R evaluate() throws Exception; 9 | } 10 | -------------------------------------------------------------------------------- /src/com.example.datastructure.chapter_04_/com/example/functional/NoValueException.java: -------------------------------------------------------------------------------- 1 | package com.example.functional; 2 | 3 | /** 4 | * Created by debasishc on 28/8/16. 5 | */ 6 | public class NoValueException extends RuntimeException { 7 | public NoValueException(String message){ 8 | super(message); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/com.example.datastructure.chapter_04_/com/example/functional/OneArgumentExpression.java: -------------------------------------------------------------------------------- 1 | package com.example.functional; 2 | 3 | /** 4 | * Created by debasishc on 28/8/16. 5 | */ 6 | @FunctionalInterface 7 | public interface OneArgumentExpression { 8 | R compute(A a); 9 | } 10 | -------------------------------------------------------------------------------- /src/com.example.datastructure.chapter_04_/com/example/functional/OneArgumentExpressionWithException.java: -------------------------------------------------------------------------------- 1 | package com.example.functional; 2 | 3 | /** 4 | * Created by debasishc on 11/9/16. 5 | */ 6 | @FunctionalInterface 7 | public interface OneArgumentExpressionWithException { 8 | R compute(A a) throws Exception; 9 | } 10 | -------------------------------------------------------------------------------- /src/com.example.datastructure.chapter_04_/com/example/functional/OneArgumentStatement.java: -------------------------------------------------------------------------------- 1 | package com.example.functional; 2 | 3 | /** 4 | * Created by debasishc on 31/8/16. 5 | */ 6 | @FunctionalInterface 7 | public interface OneArgumentStatement { 8 | void doSomething(E argument); 9 | } 10 | -------------------------------------------------------------------------------- /src/com.example.datastructure.chapter_04_/com/example/functional/OneArgumentStatementWithException.java: -------------------------------------------------------------------------------- 1 | package com.example.functional; 2 | 3 | /** 4 | * Created by debasishc on 29/1/17. 5 | */ 6 | @FunctionalInterface 7 | public interface OneArgumentStatementWithException { 8 | void doSomething(E input) throws Exception; 9 | } 10 | -------------------------------------------------------------------------------- /src/com.example.datastructure.chapter_04_/com/example/functional/Option.java: -------------------------------------------------------------------------------- 1 | package com.example.functional; 2 | 3 | /** 4 | * Created by debasishc on 28/8/16. 5 | */ 6 | public abstract class Option { 7 | public static class None extends Option{ 8 | 9 | @Override 10 | public Option flatMap(OneArgumentExpression> transformer) { 11 | return new None<>(); 12 | } 13 | 14 | @Override 15 | public E get() { 16 | throw new NoValueException("get() invoked on None"); 17 | } 18 | 19 | @Override 20 | public Option map(OneArgumentExpression transformer) { 21 | return new None<>(); 22 | } 23 | 24 | @Override 25 | public void forEach(OneArgumentStatement statement) { 26 | } 27 | } 28 | public static class Some extends Option{ 29 | E value; 30 | public Some(E value){ 31 | this.value = value; 32 | } 33 | public E get(){ 34 | return value; 35 | } 36 | public Option map(OneArgumentExpression transformer){ 37 | return Option.optionOf(transformer.compute(value)); 38 | } 39 | public Option flatMap(OneArgumentExpression> transformer){ 40 | return transformer.compute(value); 41 | } 42 | public void forEach(OneArgumentStatement statement){ 43 | statement.doSomething(value); 44 | } 45 | } 46 | 47 | public static Option optionOf(X value){ 48 | if(value == null){ 49 | return new None<>(); 50 | }else{ 51 | return new Some<>(value); 52 | } 53 | } 54 | 55 | public abstract E get(); 56 | public abstract Option map(OneArgumentExpression transformer); 57 | public abstract Option flatMap(OneArgumentExpression> transformer); 58 | public abstract void forEach(OneArgumentStatement statement); 59 | } 60 | -------------------------------------------------------------------------------- /src/com.example.datastructure.chapter_04_/com/example/functional/Person.java: -------------------------------------------------------------------------------- 1 | package com.example.functional; 2 | 3 | /** 4 | * Created by debasishc on 4/9/16. 5 | */ 6 | public class Person { 7 | private String name; 8 | private Address address; 9 | 10 | public Person(Address address, String name) { 11 | this.address = address; 12 | this.name = name; 13 | } 14 | 15 | public Option
getAddress() { 16 | return Option.optionOf(address); 17 | } 18 | 19 | public Option getName() { 20 | return Option.optionOf(name); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/com.example.datastructure.chapter_04_/com/example/functional/SampleFunctionalInterface.java: -------------------------------------------------------------------------------- 1 | package com.example.functional; 2 | 3 | /** 4 | * Created by debasishc on 27/8/16. 5 | */ 6 | @FunctionalInterface 7 | public interface SampleFunctionalInterface { 8 | int modify(int x); 9 | } 10 | -------------------------------------------------------------------------------- /src/com.example.datastructure.chapter_04_/com/example/functional/ThreeArgumentStatement.java: -------------------------------------------------------------------------------- 1 | package com.example.functional; 2 | 3 | /** 4 | * Created by debasishc on 22/12/16. 5 | */ 6 | public interface ThreeArgumentStatement { 7 | void doSomething(E e, F f, G g); 8 | } 9 | -------------------------------------------------------------------------------- /src/com.example.datastructure.chapter_04_/com/example/functional/Try.java: -------------------------------------------------------------------------------- 1 | package com.example.functional; 2 | 3 | /** 4 | * Created by debasishc on 8/9/16. 5 | */ 6 | public abstract class Try { 7 | public static Try of( 8 | NoArgumentExpressionWithException expression) { 9 | try { 10 | return new Success<>(expression.evaluate()); 11 | } catch (Exception ex) { 12 | return new Failure<>(ex); 13 | } 14 | } 15 | 16 | public abstract Try map( 17 | OneArgumentExpressionWithException expression); 18 | 19 | public abstract Try flatMap( 20 | OneArgumentExpression> expression); 21 | 22 | public abstract E get(); 23 | 24 | public abstract void forEach( 25 | OneArgumentStatement statement); 26 | 27 | public abstract Try processException( 28 | OneArgumentStatement statement); 29 | 30 | protected static class Failure extends Try { 31 | protected Exception exception; 32 | 33 | public Failure(Exception exception) { 34 | this.exception = exception; 35 | } 36 | 37 | @Override 38 | public Try flatMap( 39 | OneArgumentExpression> expression) { 40 | return new Failure<>(exception); 41 | } 42 | 43 | @Override 44 | public Try map( 45 | OneArgumentExpressionWithException expression) { 46 | return new Failure<>(exception); 47 | } 48 | 49 | @Override 50 | public E get() { 51 | throw new NoValueException( 52 | "get method invoked on Failure"); 53 | } 54 | 55 | @Override 56 | public void forEach( 57 | OneArgumentStatement statement) { 58 | 59 | } 60 | 61 | @Override 62 | public Try processException( 63 | OneArgumentStatement statement) { 64 | statement.doSomething(exception); 65 | return this; 66 | } 67 | } 68 | 69 | protected static class Success extends Try { 70 | protected E value; 71 | 72 | public Success(E value) { 73 | this.value = value; 74 | } 75 | 76 | @Override 77 | public Try flatMap( 78 | OneArgumentExpression> expression) { 79 | return expression.compute(value); 80 | } 81 | 82 | @Override 83 | public Try map( 84 | OneArgumentExpressionWithException expression) { 85 | try { 86 | return new Success<>( 87 | expression.compute(value)); 88 | } catch (Exception ex) { 89 | return new Failure<>(ex); 90 | } 91 | } 92 | 93 | @Override 94 | public E get() { 95 | return value; 96 | } 97 | 98 | @Override 99 | public void forEach( 100 | OneArgumentStatement statement) { 101 | statement.doSomething(value); 102 | } 103 | 104 | @Override 105 | public Try processException( 106 | OneArgumentStatement statement) { 107 | return this; 108 | } 109 | } 110 | 111 | } 112 | -------------------------------------------------------------------------------- /src/com.example.datastructure.chapter_04_/com/example/functional/TwoArgumentExpression.java: -------------------------------------------------------------------------------- 1 | package com.example.functional; 2 | 3 | /** 4 | * Created by debasishc on 1/9/16. 5 | */ 6 | @FunctionalInterface 7 | public interface TwoArgumentExpression { 8 | R compute(A lhs, B rhs); 9 | } 10 | -------------------------------------------------------------------------------- /src/com.example.datastructure.chapter_04_/com/example/functional/TwoArgumentStatement.java: -------------------------------------------------------------------------------- 1 | package com.example.functional; 2 | 3 | /** 4 | * Created by debasishc on 22/12/16. 5 | */ 6 | public interface TwoArgumentStatement { 7 | void doSomething(E e, F f); 8 | } 9 | -------------------------------------------------------------------------------- /src/com.example.datastructure.chapter_04_/module-info.java: -------------------------------------------------------------------------------- 1 | module com.example.datastructure.chapter_04_{ 2 | exports com.example.functional; 3 | requires com.example.datastructure.chapter_03_; 4 | } 5 | -------------------------------------------------------------------------------- /src/com.example.datastructure.chapter_05_/com/example/search/ArraySearcher.java: -------------------------------------------------------------------------------- 1 | package com.example.search; 2 | 3 | import java.util.Arrays; 4 | 5 | /** 6 | * Created by debasishc on 14/9/16. 7 | */ 8 | public class ArraySearcher { 9 | static String[] students = 10 | new String[]{"Tom", "Harry", "Merry", "Aisha", 11 | "Abdullah"}; 12 | static int[] marks = new int[]{63, 70, 65, 85, 72}; 13 | 14 | public static int linearSearch(E[] values, 15 | F valueToLookup) { 16 | for (int i = 0; i < values.length; i++) { 17 | if (values[i].equals(valueToLookup)) { 18 | return i; 19 | } 20 | } 21 | return -1; 22 | } 23 | 24 | private static , F extends E> int binarySearch( 25 | E[] sortedValues, F valueToSearch, int start, int end) { 26 | if(start>=end){ 27 | return -1; 28 | } 29 | int midIndex = (end+start)/2; 30 | int comparison = sortedValues[midIndex].compareTo(valueToSearch); 31 | if(comparison==0){ 32 | return midIndex; 33 | }else if(comparison>0){ 34 | return binarySearch(sortedValues, valueToSearch, start, midIndex); 35 | }else{ 36 | return binarySearch(sortedValues, valueToSearch, midIndex+1, end); 37 | } 38 | } 39 | 40 | private static , F extends E> int binarySearchNonRecursive( 41 | E[] sortedValues, F valueToSearch, int start, int end) { 42 | while(true) { 43 | if (start >= end) { 44 | return -1; 45 | } 46 | int midIndex = (end + start) / 2; 47 | int comparison = 48 | sortedValues[midIndex].compareTo(valueToSearch); 49 | if (comparison == 0) { 50 | return midIndex; 51 | } else if (comparison > 0) { 52 | end = midIndex; 53 | } else { 54 | start = midIndex + 1; 55 | } 56 | } 57 | } 58 | 59 | public static , F extends E> int binarySearch( 60 | E[] sortedValues, F valueToSearch) { 61 | return binarySearch(sortedValues, valueToSearch, 0, sortedValues.length); 62 | } 63 | 64 | public static Integer marksForName(String name) { 65 | int index = linearSearch(students, name); 66 | if (index >= 0) { 67 | return marks[index]; 68 | } else { 69 | return null; 70 | } 71 | } 72 | 73 | public static void main(String[] args) { 74 | Integer[] integers = 75 | new Integer[]{232, 54, 1, 213, 654, 23, 6, 72, 21}; 76 | System.out.println(linearSearch(integers, 5)); 77 | System.out.println(linearSearch(integers, 23)); 78 | Arrays.sort(integers); 79 | System.out.println(binarySearch(integers, 54)); 80 | System.out.println(binarySearch(integers, 54, 0, integers.length)); 81 | System.out.println(marksForName("Merry")); 82 | 83 | // //lets generate a random sorted array of integers. 84 | // int arraySize = 100000000; 85 | // Long array[] = new Long[arraySize]; 86 | // array[0] = (long)(Math.random()*100); 87 | // for(int i=1;i addNode(Node parent, E value){ 52 | if(parent==null){ 53 | throw new NullPointerException("Cannot add child to null parent"); 54 | }else if(parent.hostTree != this){ 55 | throw new IllegalArgumentException("Parent node not a part of this tree"); 56 | }else{ 57 | Node newNode = new Node<>(new LinkedList<>(), this, value, parent); 58 | parent.getChildren().appendLast(newNode); 59 | return newNode; 60 | } 61 | } 62 | 63 | protected void traverseDepthFirst(OneArgumentStatement processor, Node current){ 64 | processor.doSomething(current.value); 65 | current.children.forEach((n)-> traverseDepthFirst(processor, n)); 66 | } 67 | 68 | public void traverseDepthFirst(OneArgumentStatement processor){ 69 | traverseDepthFirst(processor, getRoot()); 70 | } 71 | 72 | protected void displayText(Node parent, int depth){ 73 | for(int i=0;i displayText(n, depth+1)); 78 | } 79 | protected void displayText(){ 80 | displayText(getRoot(), 0); 81 | } 82 | 83 | public void traverseDepthFirstUsingStack(OneArgumentStatement processor){ 84 | Stack> stack = new StackImplLinkedList<>(); 85 | stack.push(getRoot()); 86 | while(stack.peek()!=null){ 87 | Node current = stack.pop(); 88 | processor.doSomething(current.value); 89 | LinkedList> reverseList = new LinkedList<>(); 90 | current.children.forEach((n)->reverseList.appendFirst(n)); 91 | reverseList.forEach((n)->stack.push(n)); 92 | } 93 | } 94 | 95 | public void traverseBreadthFirst(OneArgumentStatement processor){ 96 | Queue> queue = new QueueImplLinkedList<>(); 97 | queue.enqueue(getRoot()); 98 | while(queue.peek()!=null){ 99 | Node current = queue.dequeue(); 100 | processor.doSomething(current.value); 101 | current.children.forEach((n)->queue.enqueue(n)); 102 | } 103 | } 104 | 105 | 106 | public static void main(String [] args){ 107 | Tree tree = new Tree<>(); 108 | tree.addRoot(1); 109 | Node node1 = tree.getRoot(); 110 | Node node2 = tree.addNode(node1, 5); 111 | Node node3 = tree.addNode(node1, 1); 112 | Node node4 = tree.addNode(node2, 2); 113 | Node node5 = tree.addNode(node2, 5); 114 | Node node6 = tree.addNode(node2, 9); 115 | Node node7 = tree.addNode(node3, 6); 116 | Node node8 = tree.addNode(node3, 2); 117 | Node node9 = tree.addNode(node5, 5); 118 | Node node10 = tree.addNode(node6, 9); 119 | Node node11 = tree.addNode(node6, 6); 120 | tree.displayText(); 121 | tree.traverseDepthFirst(System.out::print); 122 | System.out.println(); 123 | tree.traverseDepthFirstUsingStack(System.out::print); 124 | System.out.println(); 125 | tree.traverseBreadthFirst(System.out::print); 126 | 127 | } 128 | 129 | } 130 | -------------------------------------------------------------------------------- /src/com.example.datastructure.chapter_07_/module-info.java: -------------------------------------------------------------------------------- 1 | module com.example.datastructure.chapter_07_{ 2 | exports com.example.tree; 3 | requires com.example.datastructure.chapter_02_; 4 | requires com.example.datastructure.chapter_03_; 5 | requires com.example.datastructure.chapter_04_; 6 | } 7 | -------------------------------------------------------------------------------- /src/com.example.datastructure.chapter_08_/com/example/searchtree/AVLTree.java: -------------------------------------------------------------------------------- 1 | package com.example.searchtree; 2 | 3 | import com.example.tree.BinaryTree; 4 | 5 | 6 | /** 7 | * Created by debasishc on 1/11/16. 8 | */ 9 | public class AVLTree> extends BinarySearchTree{ 10 | public static class Node> extends BinaryTree.Node{ 11 | protected int height = 0; 12 | public Node(BinaryTree.Node parent, 13 | BinaryTree containerTree, E value) { 14 | super(parent, containerTree, value); 15 | } 16 | } 17 | 18 | @Override 19 | protected BinaryTree.Node newNode( 20 | BinaryTree.Node parent, BinaryTree containerTree, 21 | E value) { 22 | return new Node(parent, containerTree, value); 23 | } 24 | 25 | @Override 26 | protected void rotate(BinaryTree.Node node, boolean left) { 27 | Node n = (Node) node; 28 | Node child; 29 | if(left){ 30 | child = (Node) n.getRight(); 31 | }else{ 32 | child = (Node) n.getLeft(); 33 | } 34 | super.rotate(node, left); 35 | if(node!=null){ 36 | nullSafeComputeHeight(n); 37 | } 38 | if(child!=null){ 39 | nullSafeComputeHeight(child); 40 | } 41 | } 42 | 43 | protected void rebalance(Node node){ 44 | if(node==null){ 45 | return; 46 | } 47 | nullSafeComputeHeight(node); 48 | int leftHeight = nullSafeHeight((Node) node.getLeft()); 49 | int rightHeight = nullSafeHeight((Node) node.getRight()); 50 | switch (leftHeight-rightHeight){ 51 | case -1: 52 | case 0: 53 | case 1: 54 | rebalance((Node) node.getParent()); 55 | break; 56 | case 2: 57 | int childLeftHeight = nullSafeHeight( 58 | (Node) node.getLeft().getLeft()); 59 | int childRightHeight = nullSafeHeight( 60 | (Node) node.getLeft().getRight()); 61 | if(childRightHeight > childLeftHeight){ 62 | rotate(node.getLeft(), true); 63 | } 64 | Node oldParent = (Node) node.getParent(); 65 | rotate(node, false); 66 | rebalance(oldParent); 67 | break; 68 | case -2: 69 | childLeftHeight = nullSafeHeight( 70 | (Node) node.getRight().getLeft()); 71 | childRightHeight = nullSafeHeight( 72 | (Node) node.getRight().getRight()); 73 | if(childLeftHeight > childRightHeight){ 74 | rotate(node.getRight(), false); 75 | } 76 | oldParent = (Node) node.getParent(); 77 | rotate(node, true); 78 | rebalance(oldParent); 79 | break; 80 | } 81 | } 82 | 83 | @Override 84 | public BinaryTree.Node insertValue(E value) { 85 | Node node = (Node) super.insertValue(value); 86 | if(node!=null) 87 | rebalance(node); 88 | return node; 89 | } 90 | 91 | @Override 92 | public BinaryTree.Node deleteValue(E value) { 93 | Node node = (Node) super.deleteValue(value); 94 | if(node==null){ 95 | return null; 96 | } 97 | Node parentNode = (Node) node.getParent(); 98 | rebalance(parentNode); 99 | return node; 100 | } 101 | 102 | private int nullSafeHeight(Node node){ 103 | if(node==null){ 104 | return 0; 105 | }else{ 106 | return node.height; 107 | } 108 | } 109 | 110 | private void nullSafeComputeHeight(Node node){ 111 | Node left = (Node) node.getLeft(); 112 | Node right = (Node) node.getRight(); 113 | int leftHeight = left==null? 0 : left.height; 114 | int rightHeight = right==null? 0 :right.height; 115 | node.height = Math.max(leftHeight, rightHeight)+1; 116 | } 117 | 118 | protected void testSanity(Node n){ 119 | if(n==null){ 120 | return; 121 | }else{ 122 | int leftHeight = nullSafeHeight((Node) n.getLeft()); 123 | int rightHeight = nullSafeHeight((Node) n.getRight()); 124 | if(n.height != Math.max(leftHeight, rightHeight)+1){ 125 | throw new IllegalStateException("Height computation don't match"); 126 | }else if(Math.abs(leftHeight-rightHeight)>1){ 127 | throw new IllegalStateException("Unbalanced tree"); 128 | } 129 | testSanity((Node) n.getLeft()); 130 | testSanity((Node) n.getRight()); 131 | } 132 | } 133 | 134 | public static void main(String [] args){ 135 | AVLTree tree = new AVLTree<>(); 136 | for(int i=0;i<20;i++){ 137 | tree.insertValue(i); 138 | } 139 | //tree.displayText(); 140 | tree.insertValue(9); 141 | //tree.displayText(); 142 | tree.deleteValue(12); 143 | tree.deleteValue(14); 144 | tree.displayText(); 145 | //testSanity((Node) tree.getRoot()); 146 | for(int i=0;i<2000000;i++){ 147 | tree.insertValue((int)(Math.random()*10000000)); 148 | } 149 | //tree.testSanity((Node) tree.getRoot()); 150 | for(int i=0;i<2000;i++){ 151 | tree.deleteValue((int)(Math.random()*10000000)); 152 | } 153 | 154 | tree.testSanity((Node) tree.getRoot()); 155 | } 156 | } 157 | -------------------------------------------------------------------------------- /src/com.example.datastructure.chapter_08_/com/example/searchtree/BinarySearchTree.java: -------------------------------------------------------------------------------- 1 | package com.example.searchtree; 2 | 3 | import com.example.tree.BinaryTree; 4 | 5 | /** 6 | * Created by debasishc on 28/10/16. 7 | */ 8 | public class BinarySearchTree> extends BinaryTree { 9 | 10 | protected Node searchValue(E value, Node root){ 11 | if(root==null){ 12 | return null; 13 | } 14 | int comp = root.getValue().compareTo(value); 15 | if(comp == 0){ 16 | return root; 17 | }else if(comp>0){ 18 | return searchValue(value, root.getLeft()); 19 | }else{ 20 | return searchValue(value, root.getRight()); 21 | } 22 | } 23 | 24 | public Node searchValue(E value){ 25 | if(getRoot()==null){ 26 | return null; 27 | }else{ 28 | return searchValue(value, getRoot()); 29 | } 30 | } 31 | 32 | protected Node insertValue(E value, Node node){ 33 | int comp = node.getValue().compareTo(value); 34 | Node child; 35 | if(comp<0){ 36 | child = node.getRight(); 37 | if(child==null){ 38 | return addChild(node,value,false); 39 | }else{ 40 | return insertValue(value, child); 41 | } 42 | }else if(comp>0){ 43 | child = node.getLeft(); 44 | if(child==null){ 45 | return addChild(node,value,true); 46 | }else{ 47 | return insertValue(value, child); 48 | } 49 | }else{ 50 | return null; 51 | } 52 | } 53 | 54 | public Node insertValue(E value){ 55 | if(getRoot()==null){ 56 | addRoot(value); 57 | return getRoot(); 58 | }else{ 59 | return insertValue(value, getRoot()); 60 | } 61 | } 62 | 63 | protected Node getLeftMost(Node node){ 64 | if(node==null){ 65 | return null; 66 | }else if(node.getLeft()==null){ 67 | return node; 68 | }else{ 69 | return getLeftMost(node.getLeft()); 70 | } 71 | } 72 | 73 | protected Node getRightMost(Node node){ 74 | if(node==null){ 75 | return null; 76 | }else if(node.getLeft()==null){ 77 | return node; 78 | }else{ 79 | return getRightMost(node.getLeft()); 80 | } 81 | } 82 | 83 | public Node deleteValue(E value){ 84 | Node nodeToBeDeleted = searchValue(value); 85 | if(nodeToBeDeleted==null){ 86 | return null; 87 | }else{ 88 | 89 | return deleteNode(nodeToBeDeleted); 90 | } 91 | 92 | } 93 | 94 | private Node deleteNode( 95 | Node nodeToBeDeleted) { 96 | boolean direction; 97 | if(nodeToBeDeleted.getParent()!=null 98 | && nodeToBeDeleted.getParent().getLeft()==nodeToBeDeleted){ 99 | direction = true; 100 | }else{ 101 | direction = false; 102 | } 103 | if(nodeToBeDeleted.getLeft()==null && nodeToBeDeleted.getRight()==null){ 104 | deleteNodeWithSubtree(nodeToBeDeleted); 105 | return nodeToBeDeleted; 106 | }else if(nodeToBeDeleted.getLeft()==null){ 107 | if(nodeToBeDeleted.getParent() == null){ 108 | root = nodeToBeDeleted.getRight(); 109 | }else { 110 | setChild(nodeToBeDeleted.getParent(), 111 | nodeToBeDeleted.getRight(), direction); 112 | } 113 | return nodeToBeDeleted; 114 | }else if(nodeToBeDeleted.getRight()==null){ 115 | if(nodeToBeDeleted.getParent() == null){ 116 | root = nodeToBeDeleted.getLeft(); 117 | }else { 118 | setChild(nodeToBeDeleted.getParent(), 119 | nodeToBeDeleted.getLeft(), direction); 120 | } 121 | return nodeToBeDeleted; 122 | }else{ 123 | Node nodeToBeReplaced = getLeftMost(nodeToBeDeleted.getRight()); 124 | setValue(nodeToBeDeleted, nodeToBeReplaced.getValue()); 125 | deleteNode(nodeToBeReplaced); 126 | return nodeToBeReplaced; 127 | } 128 | } 129 | 130 | 131 | public static void main(String [] args){ 132 | BinarySearchTree tree = new BinarySearchTree<>(); 133 | int stored = -1; 134 | for(int i=0;i<20;i++){ 135 | int value = (int) (100*Math.random()); 136 | tree.insertValue(value); 137 | if(stored == -1 && (Math.random()>0.7 || i == 19)){ 138 | stored = value; 139 | } 140 | } 141 | tree.traverseDepthFirst((x)->System.out.print(" "+x), tree.getRoot(), DepthFirstTraversalType.INORDER); 142 | System.out.println("\n"+stored+": " +tree.searchValue(stored).getValue()); 143 | tree.displayText(); 144 | System.out.println("=========================================="); 145 | tree.deleteValue(tree.getRoot().getValue()); 146 | tree.displayText(); 147 | } 148 | 149 | } 150 | -------------------------------------------------------------------------------- /src/com.example.datastructure.chapter_08_/module-info.java: -------------------------------------------------------------------------------- 1 | module com.example.datastructure.chapter_08_{ 2 | exports com.example.searchtree; 3 | requires com.example.datastructure.chapter_02_; 4 | requires com.example.datastructure.chapter_04_; 5 | requires com.example.datastructure.chapter_05_; 6 | requires com.example.datastructure.chapter_07_; 7 | } 8 | -------------------------------------------------------------------------------- /src/com.example.datastructure.chapter_09_/com/example/priorityqueue/ArrayHeap.java: -------------------------------------------------------------------------------- 1 | package com.example.priorityqueue; 2 | 3 | import java.util.Arrays; 4 | import java.util.Comparator; 5 | import java.util.Iterator; 6 | import com.example.adt.NoSpaceException; 7 | 8 | /** 9 | * Created by debasishc on 7/11/16. 10 | */ 11 | public class ArrayHeap implements PriorityQueue{ 12 | protected E[] store; 13 | protected Comparator comparator; 14 | int numElements = 0; 15 | public ArrayHeap(int size, Comparator comparator){ 16 | store = (E[]) new Object[size]; 17 | this.comparator = comparator; 18 | } 19 | 20 | protected int parentIndex(int nodeIndex){ 21 | return ((nodeIndex+1)/2)-1; 22 | } 23 | 24 | protected int leftChildIndex(int nodeIndex){ 25 | return (nodeIndex+1)*2 -1; 26 | } 27 | 28 | protected int rightChildIndex(int nodeIndex){ 29 | return (nodeIndex+1)*2; 30 | } 31 | 32 | protected void swap(int index1, int index2){ 33 | E temp = store[index1]; 34 | store[index1] = store[index2]; 35 | store[index2] = temp; 36 | } 37 | 38 | public static void heapSort(E[] array, Comparator comparator){ 39 | ArrayHeap arrayHeap = new ArrayHeap(0, (a,b) -> comparator.compare(b,a)); 40 | arrayHeap.store = array; 41 | for(int i=0;i=0;i--){ 45 | array[i] = arrayHeap.removeMin(); 46 | } 47 | } 48 | 49 | protected void trickleUp(int position){ 50 | int parentIndex = parentIndex(position); 51 | if(position> 0 && comparator.compare(store[parentIndex], store[position])>0){ 52 | swap(position, parentIndex); 53 | trickleUp(parentIndex); 54 | } 55 | } 56 | 57 | protected void trickleDown(int position){ 58 | int leftChild = leftChildIndex(position); 59 | int rightChild = leftChild+1; 60 | if(rightChild=numElements){ 111 | System.out.println("*"); 112 | return; 113 | } 114 | System.out.println(store[parent]); 115 | displayText(leftChildIndex(parent),depth+1); 116 | displayText(rightChildIndex(parent),depth+1); 117 | } 118 | protected void displayText(){ 119 | displayText(0, 0); 120 | } 121 | 122 | public static void main(String [] args){ 123 | ArrayHeap heap = new ArrayHeap<>(200, (a,b)-> b-a); 124 | for(int i=1;i<=200;i++){ 125 | heap.insert((int)(Math.random()*1000)); 126 | } 127 | System.out.println(heap.numElements); 128 | //heap.displayText(); 129 | Integer value; 130 | while((value = heap.removeMin())!=null){ 131 | System.out.print(value+", "); 132 | } 133 | heap.displayText(); 134 | 135 | Integer[] array = new Integer[200]; 136 | for(int i=0;i<200;i++){ 137 | array[i] = (int)(Math.random()*1000); 138 | } 139 | System.out.println(Arrays.toString(array)); 140 | ArrayHeap.heapSort(array, (a,b)->a-b); 141 | System.out.println(Arrays.toString(array)); 142 | } 143 | 144 | @Override 145 | public E checkMinimum() { 146 | if(numElements==0){ 147 | return null; 148 | }else{ 149 | return store[0]; 150 | } 151 | } 152 | 153 | @Override 154 | public E dequeueMinimum() { 155 | return removeMin(); 156 | } 157 | 158 | @Override 159 | public void enqueue(E value) { 160 | insert(value); 161 | } 162 | 163 | @Override 164 | public Iterator iterator() { 165 | return new Iterator() { 166 | int nextPosition = 0; 167 | @Override 168 | public boolean hasNext() { 169 | return nextPosition implements PriorityQueue{ 10 | @Override 11 | public E checkMinimum() { 12 | return root==null? null : root.value; 13 | } 14 | 15 | @Override 16 | public E dequeueMinimum() { 17 | return removeMin(); 18 | } 19 | 20 | @Override 21 | public void enqueue(E value) { 22 | insert(value); 23 | } 24 | 25 | @Override 26 | public Iterator iterator() { 27 | return null; 28 | } 29 | 30 | protected static class Node{ 31 | protected E value; 32 | protected Node left; 33 | protected Node right; 34 | protected Node parent; 35 | public Node(E value, Node parent){ 36 | this.value = value; 37 | this.parent = parent; 38 | } 39 | } 40 | protected Node root; 41 | protected int numElements; 42 | 43 | protected Node findNodeAtPostion(int position){ 44 | if(position == 1){ 45 | return root; 46 | }else{ 47 | int side = position % 2; 48 | int parentPosition = position / 2; 49 | Node parent = findNodeAtPostion(parentPosition); 50 | switch (side){ 51 | case 0: 52 | return parent.left; 53 | case 1: 54 | return parent.right; 55 | } 56 | } 57 | return null; 58 | } 59 | 60 | public void insert(E value){ 61 | if(root==null){ 62 | root = new Node<>(value, null); 63 | }else{ 64 | Node parent = findNodeAtPostion((numElements+1)/2); 65 | int side = (numElements+1)%2; 66 | Node newNode = new Node<>(value, parent); 67 | switch (side){ 68 | case 0: 69 | parent.left = newNode; 70 | break; 71 | case 1: 72 | parent.right = newNode; 73 | break; 74 | } 75 | trickleUp(newNode); 76 | } 77 | numElements++; 78 | } 79 | 80 | public E removeMin(){ 81 | if(root==null){ 82 | return null; 83 | } 84 | Node lastElement = findNodeAtPostion(numElements); 85 | if(lastElement==root){ 86 | root = null; 87 | numElements--; 88 | return lastElement.value; 89 | } 90 | E value = root.value; 91 | root.value = lastElement.value; 92 | Node parent = lastElement.parent; 93 | if(parent.left==lastElement){ 94 | parent.left = null; 95 | }else{ 96 | parent.right=null; 97 | } 98 | numElements--; 99 | trickleDown(root); 100 | return value; 101 | } 102 | 103 | protected void swapWithParent(Node parent, boolean left){ 104 | Node node = left? parent.left:parent.right; 105 | Node leftChild = node.left; 106 | Node rightChild = node.right; 107 | Node sibling = left? parent.right:parent.left; 108 | Node grandParent = parent.parent; 109 | parent.left = leftChild; 110 | if(leftChild!=null){ 111 | leftChild.parent = parent; 112 | } 113 | parent.right = rightChild; 114 | if(rightChild!=null){ 115 | rightChild.parent = parent; 116 | } 117 | parent.parent = node; 118 | if(left){ 119 | node.right = sibling; 120 | node.left = parent; 121 | }else{ 122 | node.left = sibling; 123 | node.right = parent; 124 | } 125 | node.parent = grandParent; 126 | if(sibling!=null) 127 | sibling.parent = node; 128 | 129 | if(parent == root){ 130 | root = node; 131 | }else{ 132 | boolean parentLeft = grandParent.left==parent; 133 | if(parentLeft){ 134 | grandParent.left = node; 135 | }else{ 136 | grandParent.right = node; 137 | } 138 | } 139 | } 140 | 141 | protected void trickleUp(Node node){ 142 | if(node==root){ 143 | return; 144 | }else if(comparator.compare(node.value, node.parent.value)<0){ 145 | swapWithParent(node.parent, node.parent.left == node); 146 | trickleUp(node); 147 | } 148 | } 149 | 150 | protected void trickleDown(Node node){ 151 | if(node==null){ 152 | return; 153 | } 154 | if(node.left == null){ 155 | return; 156 | }else if(node.right == null){ 157 | if(comparator.compare(node.left.value, node.value)<0){ 158 | swapWithParent(node, true); 159 | trickleDown(node); 160 | } 161 | }else{ 162 | if(comparator.compare(node.left.value, node.right.value)<0){ 163 | if(comparator.compare(node.left.value, node.value)<0){ 164 | swapWithParent(node, true); 165 | trickleDown(node); 166 | } 167 | }else{ 168 | if(comparator.compare(node.right.value, node.value)<0){ 169 | swapWithParent(node, false); 170 | trickleDown(node); 171 | } 172 | } 173 | } 174 | 175 | } 176 | 177 | protected Comparator comparator; 178 | public LinkedHeap(Comparator comparator){ 179 | this.comparator = comparator; 180 | } 181 | 182 | protected void displayText(Node parent, int depth){ 183 | 184 | for(int i=0;i heap = new LinkedHeap<>((a,b)-> b-a); 201 | for(int i=1;i<=100;i++){ 202 | heap.insert((int)(Math.random()*1000)); 203 | } 204 | System.out.println(heap.numElements); 205 | Integer value = null; 206 | while((value = heap.removeMin())!=null){ 207 | System.out.print(value+", "); 208 | } 209 | heap.displayText(); 210 | } 211 | } 212 | -------------------------------------------------------------------------------- /src/com.example.datastructure.chapter_09_/com/example/priorityqueue/PriorityQueue.java: -------------------------------------------------------------------------------- 1 | package com.example.priorityqueue; 2 | 3 | import com.example.adt.OrderedStore; 4 | 5 | /** 6 | * Created by debasishc on 7/11/16. 7 | */ 8 | public interface PriorityQueue extends OrderedStore{ 9 | E checkMinimum(); 10 | E dequeueMinimum(); 11 | void enqueue(E value); 12 | 13 | @Override 14 | default E checkFirst(){ 15 | return checkMinimum(); 16 | } 17 | 18 | @Override 19 | default void insert(E value){ 20 | enqueue(value); 21 | } 22 | 23 | @Override 24 | default E pickFirst(){ 25 | return dequeueMinimum(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/com.example.datastructure.chapter_09_/com/example/priorityqueue/SortableLinkedList.java: -------------------------------------------------------------------------------- 1 | package com.example.priorityqueue; 2 | 3 | import java.util.Comparator; 4 | import java.util.Iterator; 5 | import java.util.NoSuchElementException; 6 | import com.example.datastructure.LinkedList; 7 | 8 | /** 9 | * This LinkedList is here only because we want to see the sorting using a priority queue 10 | */ 11 | public class SortableLinkedList extends LinkedList { 12 | 13 | public static void main(String[] args) { 14 | 15 | SortableLinkedList anotherList = new SortableLinkedList<>(); 16 | anotherList.appendFirst(4); 17 | anotherList.appendFirst(1); 18 | anotherList.appendFirst(2); 19 | anotherList.appendFirst(3); 20 | anotherList.appendLast(8); 21 | anotherList.appendLast(7); 22 | anotherList.appendLast(1); 23 | anotherList.appendLast(2); 24 | anotherList.appendLast(3); 25 | anotherList.appendLast(18); 26 | anotherList.sort((a,b)->a-b); 27 | 28 | System.out.println(anotherList); 29 | } 30 | 31 | 32 | public void sort(Comparator comparator){ 33 | PriorityQueue priorityQueue = new LinkedHeap(comparator); 34 | while (first!=null){ 35 | priorityQueue.enqueue(getFirst()); 36 | removeFirst(); 37 | } 38 | while (priorityQueue.checkMinimum()!=null){ 39 | appendLast(priorityQueue.dequeueMinimum()); 40 | } 41 | 42 | } 43 | 44 | } 45 | 46 | -------------------------------------------------------------------------------- /src/com.example.datastructure.chapter_09_/module-info.java: -------------------------------------------------------------------------------- 1 | module com.example.datastructure.chapter_09_{ 2 | exports com.example.priorityqueue; 3 | requires com.example.datastructure.chapter_02_; 4 | requires com.example.datastructure.chapter_03_; 5 | } 6 | -------------------------------------------------------------------------------- /src/com.example.datastructure.chapter_10_/com/example/graph/AdjacencyMatrixGraphWithSparseVertex.java: -------------------------------------------------------------------------------- 1 | package com.example.graph; 2 | 3 | import com.example.datastructure.LinkedList; 4 | import com.example.searchtree.BinarySearchTree; 5 | import com.example.searchtree.RedBlackTree; 6 | 7 | /** 8 | * Created by debasishc on 21/12/16. 9 | */ 10 | public class AdjacencyMatrixGraphWithSparseVertex implements Graph { 11 | 12 | private static class NullEdgeValue{}; 13 | 14 | private NullEdgeValue nullEdge = new NullEdgeValue(); 15 | private NullEdgeValue nullVertex = new NullEdgeValue(); 16 | 17 | Object [][] adjacencyMatrix = new Object[0][]; 18 | Object[] vertexValues = new Object[0]; 19 | boolean undirected; 20 | 21 | public AdjacencyMatrixGraphWithSparseVertex(boolean undirected){ 22 | this.undirected = undirected; 23 | } 24 | 25 | 26 | @Override 27 | public int addVertex() { 28 | int numVertices = adjacencyMatrix.length; 29 | Object [][] newAdjacencyMatrix = new Object[numVertices+1][]; 30 | for(int i=0;i neighborList = new LinkedList<>(); 81 | for(int i=0;i getAllVertices() { 126 | BinarySearchTree allVertices = new RedBlackTree<>(); 127 | for(int i=0;i 142 | graph = new AdjacencyMatrixGraphWithSparseVertex<>(true); 143 | for(int i=0;i<10;i++){ 144 | graph.addVertex(); 145 | } 146 | graph.addEdge(0,1); 147 | graph.addEdge(1,2); 148 | graph.addEdge(1,3); 149 | graph.addEdge(2,3); 150 | graph.addEdge(2,4); 151 | graph.addEdge(3,4); 152 | 153 | System.out.println(graph.isAdjacent(2,1)); 154 | System.out.println(graph.isAdjacent(2,5)); 155 | graph.getNeighbors(1).forEach(System.out::println); 156 | 157 | graph.removeVertex(1); 158 | System.out.println(graph.isAdjacent(3,2)); 159 | 160 | System.out.println(graph.isAdjacent(2,5)); 161 | graph.getNeighbors(2).forEach(System.out::println); 162 | 163 | graph.removeVertex(3); 164 | graph.getNeighbors(2).forEach(System.out::println); 165 | } 166 | } 167 | -------------------------------------------------------------------------------- /src/com.example.datastructure.chapter_10_/com/example/graph/CycleDetectedException.java: -------------------------------------------------------------------------------- 1 | package com.example.graph; 2 | 3 | /** 4 | * Created by debasishc on 26/12/16. 5 | */ 6 | public class CycleDetectedException extends RuntimeException { 7 | public CycleDetectedException(String message) { 8 | super(message); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/com.example.datastructure.chapter_10_/com/example/graph/GraphVertex.java: -------------------------------------------------------------------------------- 1 | package com.example.graph; 2 | 3 | /** 4 | * Created by debasishc on 20/12/16. 5 | */ 6 | public class GraphVertex implements Comparable>{ 7 | int id; 8 | V value; 9 | 10 | public GraphVertex(int id, V value) { 11 | this.id = id; 12 | this.value = value; 13 | } 14 | 15 | public int getId() { 16 | return id; 17 | } 18 | 19 | public void setId(int id) { 20 | this.id = id; 21 | } 22 | 23 | public V getValue() { 24 | return value; 25 | } 26 | 27 | public void setValue(V value) { 28 | this.value = value; 29 | } 30 | 31 | @Override 32 | public boolean equals(Object o) { 33 | if (this == o) return true; 34 | if (o == null || getClass() != o.getClass()) return false; 35 | 36 | GraphVertex that = (GraphVertex) o; 37 | 38 | return id == that.id; 39 | 40 | } 41 | 42 | @Override 43 | public int hashCode() { 44 | return id; 45 | } 46 | 47 | 48 | @Override 49 | public int compareTo(GraphVertex o) { 50 | return id - o.id; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/com.example.datastructure.chapter_10_/com/example/graph/UnionFind.java: -------------------------------------------------------------------------------- 1 | package com.example.graph; 2 | 3 | import com.example.searchtree.BinarySearchTree; 4 | import com.example.searchtree.RedBlackTree; 5 | import com.example.tree.BinaryTree; 6 | 7 | /** 8 | * Created by debasishc on 27/12/16. 9 | */ 10 | public class UnionFind> { 11 | private class Node implements Comparable{ 12 | Node parent; 13 | E object; 14 | int rank; 15 | 16 | public Node(E object) { 17 | this.object = object; 18 | rank = 0; 19 | } 20 | 21 | 22 | @Override 23 | public int compareTo(Node o) { 24 | return object.compareTo(o.object); 25 | } 26 | } 27 | 28 | BinarySearchTree allNodes = new RedBlackTree<>(); 29 | int partitionCount; 30 | 31 | public void add(E object){ 32 | Node n = new Node(object); 33 | allNodes.insertValue(n); 34 | partitionCount++; 35 | } 36 | 37 | Node findRoot(Node n){ 38 | if(n.parent==null){ 39 | return n; 40 | }else{ 41 | return findRoot(n.parent); 42 | } 43 | } 44 | 45 | public void union(E o1, E o2){ 46 | BinaryTree.Node node1 = allNodes.searchValue(new Node(o1)); 47 | BinaryTree.Node node2 = allNodes.searchValue(new Node(o2)); 48 | if(node1==null || node2==null){ 49 | throw new IllegalArgumentException("Objects not found"); 50 | } 51 | Node n1 = node1.getValue(); 52 | Node n2 = node2.getValue(); 53 | Node p1 = findRoot(n1); 54 | Node p2 = findRoot(n2); 55 | if(p1==p2){ 56 | return; 57 | } 58 | int r1 = n1.rank; 59 | int r2 = n2.rank; 60 | if(r1>r2){ 61 | p2.parent = p1; 62 | }else if(r2>r1){ 63 | p1.parent = p2; 64 | }else{ 65 | p2.parent = p1; 66 | p1.rank++; 67 | } 68 | partitionCount--; 69 | 70 | } 71 | 72 | public E find(E object){ 73 | BinaryTree.Node node1 = allNodes.searchValue(new Node(object)); 74 | if(node1==null){ 75 | throw new IllegalArgumentException("Objects not found"); 76 | } 77 | Node n = node1.getValue(); 78 | return findRoot(n).object; 79 | } 80 | 81 | public int getPartitionCount() { 82 | return partitionCount; 83 | } 84 | 85 | public static void main(String [] args){ 86 | UnionFind unionFind = new UnionFind<>(); 87 | 88 | for(int i=0;i<10;i++){ 89 | unionFind.add(i); 90 | } 91 | 92 | unionFind.union(0,2); 93 | unionFind.union(0,3); 94 | unionFind.union(4,3); 95 | unionFind.union(9,0); 96 | 97 | for(int i=0;i<10;i++){ 98 | System.out.println(i+ " -> "+ unionFind.find(i)); 99 | } 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /src/com.example.datastructure.chapter_10_/module-info.java: -------------------------------------------------------------------------------- 1 | module com.example.datastructure.chapter_10_{ 2 | exports com.example.graph; 3 | 4 | requires com.example.datastructure.chapter_02_; 5 | requires com.example.datastructure.chapter_03_; 6 | requires com.example.datastructure.chapter_04_; 7 | requires com.example.datastructure.chapter_07_; 8 | requires com.example.datastructure.chapter_08_; 9 | requires com.example.datastructure.chapter_09_; 10 | } 11 | -------------------------------------------------------------------------------- /src/com.example.datastructure.chapter_11_/com/example/reactive/Consumer.java: -------------------------------------------------------------------------------- 1 | package com.example.reactive; 2 | 3 | /** 4 | * Created by debasishc on 13/1/17. 5 | */ 6 | public interface Consumer { 7 | void onMessage(E message); 8 | default void onError(Exception error){ 9 | error.printStackTrace(); 10 | } 11 | default void onComplete(){ 12 | 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/com.example.datastructure.chapter_11_/com/example/reactive/EventConsumer.java: -------------------------------------------------------------------------------- 1 | package com.example.reactive; 2 | 3 | import com.example.functional.OneArgumentStatement; 4 | import com.example.functional.OneArgumentStatementWithException; 5 | 6 | /** 7 | * Created by debasishc on 29/1/17. 8 | */ 9 | public abstract class EventConsumer { 10 | OneArgumentStatementWithException consumptionCode; 11 | EventStream eventStream; 12 | Task taskList = null; 13 | private ProducerConsumerQueue queue; 14 | private OneArgumentStatement errorHandler = (ex)->ex.printStackTrace(); 15 | class StreamEvent{ 16 | Object value; 17 | Task task; 18 | } 19 | 20 | EventConsumer( 21 | OneArgumentStatementWithException consumptionCode, 22 | EventStream eventStream) { 23 | this.consumptionCode = consumptionCode; 24 | this.eventStream = eventStream; 25 | taskList = eventStreamToTask(eventStream); 26 | } 27 | private Task eventStreamToTask(EventStream stream){ 28 | Task t = new ProcessorTask(consumptionCode); 29 | EventStream s = stream; 30 | while(s.previous !=null){ 31 | if(s.mapper!=null) 32 | t = new MapperTask(s.mapper, t); 33 | else if(s.filter!=null){ 34 | t = new FilterTask(s.filter, t); 35 | } 36 | s = s.previous; 37 | } 38 | return t; 39 | } 40 | 41 | public EventConsumer onError(OneArgumentStatement errorHandler){ 42 | EventConsumer consumer = new EventConsumer(consumptionCode, eventStream) { }; 43 | consumer.taskList = taskList; 44 | consumer.errorHandler = errorHandler; 45 | return consumer; 46 | } 47 | 48 | class ConsumerCodeContainer implements Consumer{ 49 | @Override 50 | public void onError(Exception error) { 51 | errorHandler.doSomething(error); 52 | } 53 | 54 | @Override 55 | public void onMessage(StreamEvent evt) { 56 | if(evt.task instanceof ProcessorTask){ 57 | try { 58 | ((ProcessorTask) evt.task).processor 59 | .doSomething(evt.value); 60 | } catch (Exception e) { 61 | queue.sendError(e); 62 | } 63 | }else if(evt.task instanceof FilterTask){ 64 | StreamEvent nextEvent = new StreamEvent(); 65 | try { 66 | if((Boolean)((FilterTask) evt.task).filter.compute(evt.value)) { 67 | nextEvent.task = 68 | ((FilterTask) evt.task).nextTask; 69 | nextEvent.value = evt.value; 70 | queue.produce(nextEvent); 71 | } 72 | } catch (Exception e) { 73 | queue.sendError(e); 74 | } 75 | }else if(evt.task instanceof MapperTask){ 76 | StreamEvent nextEvent = new StreamEvent(); 77 | try { 78 | nextEvent.value = ((MapperTask) evt.task).mapper.compute(evt.value); 79 | nextEvent.task = ((MapperTask) evt.task).nextTask; 80 | queue.produce(nextEvent); 81 | } catch (Exception e) { 82 | queue.sendError(e); 83 | } 84 | } 85 | } 86 | } 87 | public void process(int bufferSize, int numberOfProducerThreads, int numberOfConsumerThreads) { 88 | queue = new ProducerConsumerQueue<>(bufferSize, numberOfConsumerThreads, 89 | new ConsumerCodeContainer()); 90 | EventStream s = eventStream; 91 | while(s.previous !=null){ 92 | s = s.previous; 93 | } 94 | EventStream startingStream = s; 95 | Runnable producerRunnable = ()->{ 96 | while(true){ 97 | Object value = startingStream.read(); 98 | if(value==null){ 99 | break; 100 | } 101 | StreamEvent nextEvent = new StreamEvent(); 102 | try { 103 | nextEvent.value = value; 104 | nextEvent.task = taskList; 105 | queue.produceExternal(nextEvent); 106 | } catch (Exception e) { 107 | queue.sendError(e); 108 | } 109 | } 110 | try { 111 | queue.markCompleted(); 112 | } catch (InterruptedException e) { 113 | e.printStackTrace(); 114 | } 115 | }; 116 | Thread [] producerThreads = new Thread[numberOfProducerThreads]; 117 | for(int i=0;i { 10 | EventStream previous; 11 | OneArgumentExpressionWithException mapper; 12 | OneArgumentExpressionWithException filter; 13 | public EventStream map(OneArgumentExpressionWithException mapper){ 14 | EventStream mapped = new EventStream() { 15 | 16 | @Override 17 | public R read() { 18 | return null; 19 | } 20 | }; 21 | mapped.mapper = mapper; 22 | mapped.previous = this; 23 | return mapped; 24 | } 25 | public EventStream filter(OneArgumentExpressionWithException filter){ 26 | EventStream mapped = new EventStream() { 27 | 28 | @Override 29 | public E read() { 30 | return null; 31 | } 32 | }; 33 | mapped.filter = filter; 34 | mapped.previous = this; 35 | return mapped; 36 | } 37 | public EventConsumer consume(OneArgumentStatementWithException consumer){ 38 | EventConsumer eventConsumer = new EventConsumer(consumer, this) { 39 | }; 40 | return eventConsumer; 41 | } 42 | public abstract E read(); 43 | 44 | public static void main(String [] args){ 45 | EventStream stream = new EventStream() { 46 | Long next = 1l; 47 | @Override 48 | public Long read() { 49 | Long ret = next++; 50 | if(ret<=5_000_000L){ 51 | return ret; 52 | } 53 | return null; 54 | } 55 | }; 56 | stream.map((x)->x/2).filter((x)->x>1) 57 | .filter(EventStream::isPerfect) 58 | .map((x)->x) 59 | .consume((x)->{System.out.println(x);}) 60 | .onError((x)->System.out.println(x)) 61 | .process(4096,1,3); 62 | 63 | } 64 | public static boolean isPrime(long x){ 65 | long div = 2; 66 | while(true){ 67 | if(x%div==0){ 68 | return false; 69 | } 70 | long quotient = x/div; 71 | if(quotient='0' && nextChar<='9') { 37 | value = value * 10 + (nextChar - '0'); 38 | }else{ 39 | break; 40 | } 41 | 42 | } 43 | return value; 44 | } 45 | 46 | public static void main(String [] args) throws Exception{ 47 | long startTime = System.currentTimeMillis(); 48 | FileReader reader = new FileReader("com-orkut.ungraph.txt"); 49 | while(true){ 50 | int val = reader.readIntFromText(); 51 | if(val == 0){ 52 | break; 53 | } 54 | 55 | } 56 | long endTime = System.currentTimeMillis(); 57 | System.out.println("Time Take: "+(endTime-startTime)); 58 | 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /src/com.example.datastructure.chapter_11_/com/example/reactive/FilterTask.java: -------------------------------------------------------------------------------- 1 | package com.example.reactive; 2 | 3 | import com.example.functional.OneArgumentExpressionWithException; 4 | 5 | /** 6 | * Created by debasishc on 30/1/17. 7 | */ 8 | public class FilterTask implements Task{ 9 | OneArgumentExpressionWithException filter; 10 | Task nextTask; 11 | 12 | public FilterTask( 13 | OneArgumentExpressionWithException filter, 14 | Task nextTask) { 15 | this.filter = filter; 16 | this.nextTask = nextTask; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/com.example.datastructure.chapter_11_/com/example/reactive/FriendCountProblem.java: -------------------------------------------------------------------------------- 1 | package com.example.reactive; 2 | 3 | import com.example.datastructure.Array; 4 | import com.example.search.ArraySearcher; 5 | import com.example.sort.ArraySorter; 6 | import com.example.searchtree.AVLTree; 7 | import com.example.tree.BinaryTree; 8 | 9 | import java.io.BufferedReader; 10 | import java.io.BufferedWriter; 11 | import java.io.IOException; 12 | import java.io.PrintStream; 13 | import java.nio.file.Files; 14 | import java.nio.file.Paths; 15 | import java.util.Arrays; 16 | import java.util.concurrent.atomic.AtomicInteger; 17 | 18 | /** 19 | * Created by debasishc on 17/1/17. 20 | */ 21 | public class FriendCountProblem { 22 | private static final String USER_LIST_FILE = "ulist"; 23 | private static final String EDGES_PATH = "com-orkut.ungraph.txt"; 24 | private static final String OUTPUT_FILE_PATH = "output"; 25 | 26 | public static void main(String [] args) 27 | throws Exception { 28 | long start = System.currentTimeMillis(); 29 | FileReader userListReader = new FileReader(USER_LIST_FILE); 30 | 31 | int count = 0; 32 | 33 | while(true){ 34 | 35 | int lineValue = userListReader.readIntFromText(); 36 | if(lineValue==0){ 37 | break; 38 | } 39 | count++; 40 | } 41 | 42 | Integer [] keys = new Integer[count]; 43 | AtomicInteger [] values = new AtomicInteger[count]; 44 | 45 | userListReader = new FileReader(USER_LIST_FILE); 46 | 47 | 48 | int index = 0; 49 | 50 | while(true){ 51 | 52 | int uid = userListReader.readIntFromText(); 53 | if(uid==0){ 54 | break; 55 | } 56 | keys[index] = uid; 57 | values[index] = new AtomicInteger(0); 58 | index++; 59 | 60 | } 61 | ArraySorter.quicksort(keys,(a,b)->a-b); 62 | ProducerConsumerQueue queue = new ProducerConsumerQueue<>(4092, 2, (v)->{ 63 | int pos = ArraySearcher.binarySearch(keys,v); 64 | if(pos<0){ 65 | return; 66 | } 67 | values[pos].incrementAndGet(); 68 | }); 69 | FileReader edgeListFileReader = new FileReader(EDGES_PATH); 70 | while(true){ 71 | int val = edgeListFileReader.readIntFromText(); 72 | if(val == 0){ 73 | break; 74 | } 75 | queue.produce(val); 76 | } 77 | queue.markCompleted(); 78 | queue.joinThreads(); 79 | 80 | PrintStream out = new PrintStream(OUTPUT_FILE_PATH); 81 | for(int i=0;i queue = new ProducerConsumerQueue<>(4096, 4, (x)->{ 40 | if(isPerfect(x)){ 41 | System.out.println(x); 42 | } 43 | }); 44 | 45 | for(long i=2;i<5_00_000;i++){ 46 | queue.produce(i); 47 | } 48 | queue.markCompleted(); 49 | queue.joinThreads(); 50 | System.out.println("Time in ms: "+(System.currentTimeMillis()-start)); 51 | } 52 | 53 | public static void findPerfectNumbersWithFunctionalAPI(){ 54 | long start = System.currentTimeMillis(); 55 | EventStream stream = new EventStream() { 56 | AtomicLong next = new AtomicLong(0L); 57 | @Override 58 | public Long read() { 59 | Long ret = next.incrementAndGet(); 60 | if(ret<=5_00_000L){ 61 | return ret; 62 | } 63 | return null; 64 | } 65 | }; 66 | stream.filter((x)->x>1) 67 | .filter(EventStream::isPerfect) 68 | .consume((x)->{System.out.println(x);}) 69 | .onError((x)->System.out.println(x)) 70 | .process(4096,1,4); 71 | 72 | System.out.println("Time in ms: "+(System.currentTimeMillis()-start)); 73 | } 74 | 75 | public static void main(String [] args) 76 | throws InterruptedException { 77 | findPerfectNumberWithProducerConsumer(); 78 | findPerfectNumbersWithFunctionalAPI(); 79 | findPerfectNumberWithSingleThread(); 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /src/com.example.datastructure.chapter_11_/com/example/reactive/ProcessorTask.java: -------------------------------------------------------------------------------- 1 | package com.example.reactive; 2 | 3 | import com.example.functional.OneArgumentStatement; 4 | import com.example.functional.OneArgumentStatementWithException; 5 | 6 | /** 7 | * Created by debasishc on 29/1/17. 8 | */ 9 | public class ProcessorTask implements Task{ 10 | OneArgumentStatementWithException processor; 11 | 12 | public ProcessorTask( 13 | OneArgumentStatementWithException processor) { 14 | this.processor = processor; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/com.example.datastructure.chapter_11_/com/example/reactive/ProducerConsumerGarbageFreeQueue.java: -------------------------------------------------------------------------------- 1 | package com.example.reactive; 2 | 3 | import com.example.functional.NoArgumentExpression; 4 | import com.example.functional.TwoArgumentStatement; 5 | 6 | import java.io.File; 7 | import java.io.PrintStream; 8 | 9 | /** 10 | * Created by debasishc on 17/1/17. 11 | */ 12 | public class ProducerConsumerGarbageFreeQueue { 13 | enum EventType{ 14 | INVOCATION, ERROR, COMPLETION 15 | } 16 | public class Event{ 17 | E value; 18 | Exception error; 19 | EventType eventType; 20 | } 21 | ThreadSafeFixedLengthSpinlockGarbageFreeQueue queue; 22 | boolean alive = true; 23 | Thread [] threads; 24 | NoArgumentExpression eventCreator; 25 | TwoArgumentStatement eventCopier; 26 | 27 | public ProducerConsumerGarbageFreeQueue(int bufferSize, int threadCount, Consumer consumer, 28 | NoArgumentExpression creator, 29 | TwoArgumentStatement copier){ 30 | eventCreator = () -> { 31 | Event evt = new Event(); 32 | evt.value = creator.value(); 33 | return evt; 34 | }; 35 | eventCopier = (t,s)->{ 36 | copier.doSomething(t.value,s.value); 37 | t.error = s.error; 38 | t.eventType = s.eventType; 39 | }; 40 | queue = new ThreadSafeFixedLengthSpinlockGarbageFreeQueue<>(bufferSize, 41 | eventCreator, eventCopier); 42 | threads = new Thread[threadCount]; 43 | Runnable consumerCode = ()->{ 44 | try{ 45 | Event e = eventCreator.value(); 46 | while(alive || queue.currentElementCount()>0){ 47 | queue.dequeue(e); 48 | switch (e.eventType) { 49 | case INVOCATION: 50 | consumer.onMessage(e.value); 51 | break; 52 | case ERROR: 53 | consumer.onError(e.error); 54 | break; 55 | case COMPLETION: 56 | alive = false; 57 | consumer.onComplete(); 58 | } 59 | } 60 | 61 | queue.killDequeuers(); 62 | 63 | } catch (InterruptedException e) { 64 | 65 | } finally{ 66 | 67 | } 68 | }; 69 | for(int i=0;i 116 | queue = new ProducerConsumerGarbageFreeQueue<>(1024, 20, out::println, 117 | ()->new MutableInteger(), (t,s)->t.value = s.value); 118 | long start = System.currentTimeMillis(); 119 | ProducerConsumerGarbageFreeQueue.Event event = null; 120 | MutableInteger mutableInteger = new MutableInteger(); 121 | for(int i=0;i<1000000;i++){ 122 | mutableInteger.value = i; 123 | event = queue.produce(mutableInteger, event); 124 | } 125 | queue.markCompleted(); 126 | queue.joinThreads(); 127 | out.flush(); 128 | out.close(); 129 | System.out.println("Time in ms: "+(System.currentTimeMillis()-start)); 130 | 131 | } 132 | } 133 | -------------------------------------------------------------------------------- /src/com.example.datastructure.chapter_11_/com/example/reactive/ProducerConsumerQueue.java: -------------------------------------------------------------------------------- 1 | package com.example.reactive; 2 | 3 | import java.io.File; 4 | import java.io.PrintStream; 5 | 6 | /** 7 | * Created by debasishc on 17/1/17. 8 | */ 9 | public class ProducerConsumerQueue { 10 | enum EventType{ 11 | INVOCATION, ERROR, COMPLETION 12 | } 13 | class Event{ 14 | E value; 15 | Exception error; 16 | EventType eventType; 17 | } 18 | ThreadSafeFixedLengthSpinlockQueue queue; 19 | boolean alive = true; 20 | Thread [] threads; 21 | 22 | public ProducerConsumerQueue(int bufferSize, int threadCount, Consumer consumer){ 23 | queue = new ThreadSafeFixedLengthSpinlockQueue<>(bufferSize); 24 | threads = new Thread[threadCount]; 25 | Runnable consumerCode = ()->{ 26 | try{ 27 | while(alive || queue.currentElementCount()>0){ 28 | Event e = queue.dequeue(); 29 | switch (e.eventType) { 30 | case INVOCATION: 31 | consumer.onMessage(e.value); 32 | break; 33 | case ERROR: 34 | consumer.onError(e.error); 35 | break; 36 | case COMPLETION: 37 | alive = false; 38 | consumer.onComplete(); 39 | } 40 | } 41 | 42 | queue.killDequeuers(); 43 | 44 | } catch (InterruptedException e) { 45 | 46 | } finally{ 47 | 48 | } 49 | }; 50 | for(int i=0;i queue = new ProducerConsumerQueue<>(1024, 20, out::println); 93 | long start = System.currentTimeMillis(); 94 | for(int i=0;i<5_00_000;i++){ 95 | queue.produce(i); 96 | } 97 | queue.markCompleted(); 98 | queue.joinThreads(); 99 | out.flush(); 100 | out.close(); 101 | System.out.println("Time in ms: "+(System.currentTimeMillis()-start)); 102 | 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /src/com.example.datastructure.chapter_11_/com/example/reactive/SemaphoreExample.java: -------------------------------------------------------------------------------- 1 | package com.example.reactive; 2 | 3 | import java.util.concurrent.Semaphore; 4 | 5 | /** 6 | * Created by debasishc on 24/1/17. 7 | */ 8 | public class SemaphoreExample { 9 | volatile int threadSafeInt = 0; 10 | Semaphore semaphore = new Semaphore(1); 11 | public int incremementAndGet() throws InterruptedException{ 12 | semaphore.acquire(); 13 | int previousValue = threadSafeInt++; 14 | semaphore.release(); 15 | return previousValue; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/com.example.datastructure.chapter_11_/com/example/reactive/Task.java: -------------------------------------------------------------------------------- 1 | package com.example.reactive; 2 | 3 | /** 4 | * Created by debasishc on 29/1/17. 5 | */ 6 | public interface Task { 7 | } 8 | -------------------------------------------------------------------------------- /src/com.example.datastructure.chapter_11_/com/example/reactive/ThreadSafeCounter.java: -------------------------------------------------------------------------------- 1 | package com.example.reactive; 2 | 3 | import java.util.concurrent.atomic.AtomicInteger; 4 | 5 | /** 6 | * Created by debasishc on 24/1/17. 7 | */ 8 | public class ThreadSafeCounter { 9 | AtomicInteger counter; 10 | public int incrementAndGet(){ 11 | while (true){ 12 | int value = counter.get(); 13 | if(counter.compareAndSet(value, value+1)){ 14 | return value; 15 | } 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/com.example.datastructure.chapter_11_/com/example/reactive/ThreadSafeFixedLengthBlockingQueue.java: -------------------------------------------------------------------------------- 1 | package com.example.reactive; 2 | 3 | import java.io.File; 4 | import java.io.PrintStream; 5 | import java.util.concurrent.Semaphore; 6 | import java.util.concurrent.TimeUnit; 7 | import java.util.concurrent.atomic.AtomicInteger; 8 | 9 | /** 10 | * Created by debasishc on 13/1/17. 11 | */ 12 | public class ThreadSafeFixedLengthBlockingQueue { 13 | Semaphore underflowSemaphore; 14 | Semaphore overflowSemaphore; 15 | AtomicInteger nextEnqueueIndex; 16 | AtomicInteger nextDequeueIndex; 17 | E[] store; 18 | Semaphore [] enqueueLocks; 19 | Semaphore [] dequeueLocks; 20 | int length; 21 | boolean alive = true; 22 | public ThreadSafeFixedLengthBlockingQueue(int length){ 23 | this.length = length; 24 | store = (E[]) new Object[length]; 25 | nextEnqueueIndex = new AtomicInteger(); 26 | nextDequeueIndex = new AtomicInteger(); 27 | underflowSemaphore = new Semaphore(length); 28 | overflowSemaphore = new Semaphore(length); 29 | underflowSemaphore.acquireUninterruptibly(length); 30 | enqueueLocks = new Semaphore[length]; 31 | dequeueLocks = new Semaphore[length]; 32 | for(int i=0;i 74 | queue = new ThreadSafeFixedLengthBlockingQueue<>(4096); 75 | PrintStream out = new PrintStream(new File("output")); 76 | long start = System.currentTimeMillis(); 77 | Runnable dequeer = ()->{ 78 | while(true) { 79 | int value = 0; 80 | try { 81 | value = queue.dequeue(); 82 | } catch (InterruptedException e) { 83 | e.printStackTrace(); 84 | } 85 | out.println(Thread.currentThread().getId() + 86 | " " + (System.currentTimeMillis()-start) +" " + value); 87 | 88 | } 89 | }; 90 | Runnable dequeer2 = ()->{ 91 | while(true) { 92 | int value = 0; 93 | try { 94 | value = queue.dequeue(); 95 | } catch (InterruptedException e) { 96 | e.printStackTrace(); 97 | } 98 | out.println(Thread.currentThread().getId() + 99 | " " + (System.currentTimeMillis()-start) +" " + value); 100 | } 101 | }; 102 | Runnable enqueer = ()->{ 103 | for(int i=0;i<1000000;i++) { 104 | try { 105 | queue.enqueue(i); 106 | } catch (InterruptedException e) { 107 | e.printStackTrace(); 108 | } 109 | } 110 | }; 111 | for(int i=0;i<2;i++){ 112 | new Thread(enqueer).start(); 113 | } 114 | for(int i=0;i<10;i++){ 115 | new Thread(dequeer).start(); 116 | } 117 | //new Thread(dequeer2).start(); 118 | } 119 | } 120 | -------------------------------------------------------------------------------- /src/com.example.datastructure.chapter_11_/com/example/reactive/ThreadSafeFixedLengthSpinlockGarbageFreeQueue.java: -------------------------------------------------------------------------------- 1 | package com.example.reactive; 2 | 3 | import com.example.functional.NoArgumentExpression; 4 | import com.example.functional.TwoArgumentStatement; 5 | 6 | import java.io.File; 7 | import java.io.PrintStream; 8 | import java.util.concurrent.atomic.AtomicBoolean; 9 | import java.util.concurrent.atomic.AtomicInteger; 10 | 11 | /** 12 | * Created by debasishc on 13/1/17. 13 | */ 14 | public class ThreadSafeFixedLengthSpinlockGarbageFreeQueue { 15 | volatile int nextEnqueueIndex; 16 | volatile int nextDequeueIndex; 17 | E[] store; 18 | AtomicBoolean[] enqueueLocks; 19 | AtomicBoolean[] dequeueLocks; 20 | AtomicInteger currentElementCount = new AtomicInteger(0); 21 | int length; 22 | volatile boolean alive = true; 23 | TwoArgumentStatement copier; 24 | public ThreadSafeFixedLengthSpinlockGarbageFreeQueue(int length, 25 | NoArgumentExpression creator, 26 | TwoArgumentStatement copier){ 27 | this.length = length; 28 | this.copier = copier; 29 | store = (E[]) new Object[length]; 30 | enqueueLocks = new AtomicBoolean[length]; 31 | dequeueLocks = new AtomicBoolean[length]; 32 | for(int i=0;i 80 | // queue = new ThreadSafeFixedLengthSpinlockGarbageFreeQueue<>(4096); 81 | // PrintStream out = new PrintStream(new File("output")); 82 | // long start = System.currentTimeMillis(); 83 | // Runnable dequeer = ()->{ 84 | // while(true) { 85 | // int value = 0; 86 | // try { 87 | // value = queue.dequeue(); 88 | // } catch (InterruptedException e) { 89 | // e.printStackTrace(); 90 | // } 91 | // out.println(Thread.currentThread().getId() + 92 | // " " + (System.currentTimeMillis()-start) +" " + value); 93 | // 94 | // } 95 | // }; 96 | // Runnable dequeer2 = ()->{ 97 | // while(true) { 98 | // int value = 0; 99 | // try { 100 | // value = queue.dequeue(); 101 | // } catch (InterruptedException e) { 102 | // e.printStackTrace(); 103 | // } 104 | // out.println(Thread.currentThread().getId() + 105 | // " " + (System.currentTimeMillis()-start) +" " + value); 106 | // } 107 | // }; 108 | // Runnable enqueer = ()->{ 109 | // for(int i=0;i<1000000;i++) { 110 | // try { 111 | // queue.enqueue(i); 112 | // } catch (InterruptedException e) { 113 | // e.printStackTrace(); 114 | // } 115 | // } 116 | // }; 117 | // for(int i=0;i<2;i++){ 118 | // new Thread(enqueer).start(); 119 | // } 120 | // for(int i=0;i<10;i++){ 121 | // new Thread(dequeer).start(); 122 | // } 123 | // //new Thread(dequeer2).start(); 124 | } 125 | } 126 | -------------------------------------------------------------------------------- /src/com.example.datastructure.chapter_11_/com/example/reactive/ThreadSafeFixedLengthSpinlockQueue.java: -------------------------------------------------------------------------------- 1 | package com.example.reactive; 2 | 3 | import java.io.File; 4 | import java.io.PrintStream; 5 | import java.util.concurrent.Semaphore; 6 | import java.util.concurrent.TimeUnit; 7 | import java.util.concurrent.atomic.AtomicBoolean; 8 | import java.util.concurrent.atomic.AtomicInteger; 9 | 10 | /** 11 | * Created by debasishc on 13/1/17. 12 | */ 13 | public class ThreadSafeFixedLengthSpinlockQueue { 14 | int nextEnqueueIndex; 15 | int nextDequeueIndex; 16 | E[] store; 17 | AtomicBoolean[] enqueueLocks; 18 | AtomicBoolean[] dequeueLocks; 19 | AtomicInteger currentElementCount = new AtomicInteger(0); 20 | int length; 21 | volatile boolean alive = true; 22 | public ThreadSafeFixedLengthSpinlockQueue(int length){ 23 | this.length = length; 24 | store = (E[]) new Object[length]; 25 | enqueueLocks = new AtomicBoolean[length]; 26 | dequeueLocks = new AtomicBoolean[length]; 27 | for(int i=0;i=halfLength 71 | || (!currentElementCount.compareAndSet(numberOfElements, numberOfElements+1))){ 72 | enqueueLocks[index].set(false); 73 | continue; 74 | } 75 | store[index] = value; 76 | dequeueLocks[index].set(false); 77 | return; 78 | } 79 | } 80 | } 81 | 82 | public int currentElementCount(){ 83 | return currentElementCount.get(); 84 | } 85 | 86 | public void killDequeuers(){ 87 | alive = false; 88 | } 89 | 90 | 91 | public static void main(String [] args) 92 | throws Exception { 93 | final ThreadSafeFixedLengthSpinlockQueue 94 | queue = new ThreadSafeFixedLengthSpinlockQueue<>(32); 95 | PrintStream out = new PrintStream(new File("output")); 96 | long start = System.currentTimeMillis(); 97 | Runnable dequeer = ()->{ 98 | while(true) { 99 | int value = 0; 100 | try { 101 | value = queue.dequeue(); 102 | } catch (InterruptedException e) { 103 | break; 104 | } 105 | out.println(Thread.currentThread().getId() + 106 | " " + (System.currentTimeMillis()-start) +" " + value); 107 | 108 | } 109 | }; 110 | Runnable dequeer2 = ()->{ 111 | while(true) { 112 | int value = 0; 113 | try { 114 | value = queue.dequeue(); 115 | if(value>5) 116 | queue.enqueue(value/2); 117 | } catch (InterruptedException e) { 118 | break; 119 | } 120 | out.println(Thread.currentThread().getId() + 121 | " " + (System.currentTimeMillis()-start) +" " + value); 122 | } 123 | }; 124 | Runnable enqueer = ()->{ 125 | for(int i=0;i<10000;i++) { 126 | try { 127 | queue.enqueueProducerOnly(16); 128 | } catch (InterruptedException e) { 129 | e.printStackTrace(); 130 | } 131 | } 132 | while (queue.currentElementCount()>0); 133 | queue.killDequeuers(); 134 | }; 135 | for(int i=0;i<2;i++){ 136 | new Thread(enqueer).start(); 137 | } 138 | for(int i=0;i<10;i++){ 139 | new Thread(dequeer2).start(); 140 | } 141 | //new Thread(dequeer2).start(); 142 | } 143 | } 144 | -------------------------------------------------------------------------------- /src/com.example.datastructure.chapter_11_/module-info.java: -------------------------------------------------------------------------------- 1 | module com.example.datastructure.chapter_11_{ 2 | exports com.example.reactive; 3 | requires com.example.datastructure.chapter_02_; 4 | requires com.example.datastructure.chapter_03_; 5 | requires com.example.datastructure.chapter_04_; 6 | requires com.example.datastructure.chapter_05_; 7 | requires com.example.datastructure.chapter_06_; 8 | requires com.example.datastructure.chapter_07_; 9 | requires com.example.datastructure.chapter_08_; 10 | requires com.example.datastructure.chapter_09_; 11 | } 12 | --------------------------------------------------------------------------------