From d9967e0e567ae377d66ef0df911a3b7d6a72e158 Mon Sep 17 00:00:00 2001 From: Ramy-Badr-Ahmed Date: Sat, 24 Aug 2024 22:45:26 +0200 Subject: [PATCH 01/16] Added Disjoint Sets Data Structure --- DIRECTORY.md | 1 + src/DataStructures/DisjointSets.hs | 64 ++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 src/DataStructures/DisjointSets.hs diff --git a/DIRECTORY.md b/DIRECTORY.md index 3594d0f..ccacd62 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -19,6 +19,7 @@ * [Binarytree](https://github.com/TheAlgorithms/Haskell/blob/master/src/BinaryTree/BinaryTree.hs) * Datastructures * [Maxheap](https://github.com/TheAlgorithms/Haskell/blob/master/src/DataStructures/MaxHeap.hs) + * [Disjointsets](https://github.com/TheAlgorithms/Haskell/blob/master/src/DataStructures/DisjointSets.hs) * Graph * [Dfs](https://github.com/TheAlgorithms/Haskell/blob/master/src/Graph/Dfs.hs) * [Directedgraph](https://github.com/TheAlgorithms/Haskell/blob/master/src/Graph/DirectedGraph.hs) diff --git a/src/DataStructures/DisjointSets.hs b/src/DataStructures/DisjointSets.hs new file mode 100644 index 0000000..434ba2a --- /dev/null +++ b/src/DataStructures/DisjointSets.hs @@ -0,0 +1,64 @@ +import Data.Array.ST +import Control.Monad.ST +import Data.STRef + +-- Disjoint Set Node represented as an index in an array +type Node = Int + +-- Union-Find structure +type DisjointSet s = (STArray s Node Node, STArray s Node Int) + +-- Initialize the disjoint set with each node being its own parent and rank zero +makeSet :: Int -> ST s (DisjointSet s) +makeSet n = do + parentArray <- newListArray (0, n-1) [0..n-1] + rankArray <- newListArray (0, n-1) (replicate n 0) + return (parentArray, rankArray) + +-- Find with path compression +findSet :: DisjointSet s -> Node -> ST s Node +findSet (parentArray, rankArray) x = do + parent <- readArray parentArray x + if parent == x + then return x + else do + root <- findSet (parentArray, rankArray) parent + writeArray parentArray x root + return root + +-- Union by rank +unionSet :: DisjointSet s -> Node -> Node -> ST s () +unionSet (parentArray, rankArray) x y = do + rootX <- findSet (parentArray, rankArray) x + rootY <- findSet (parentArray, rankArray) y + if rootX /= rootY + then do + rankX <- readArray rankArray rootX + rankY <- readArray rankArray rootY + if rankX > rankY + then writeArray parentArray rootY rootX + else if rankX < rankY + then writeArray parentArray rootX rootY + else do + writeArray parentArray rootY rootX + writeArray rankArray rootY (rankY + 1) + else return () + +-- Example usage +example :: Int -> [(Node, Node)] -> [Node] -> [Node] +example n unions finds = runST $ do + ds <- makeSet n + mapM_ (uncurry $ unionSet ds) unions + mapM (findSet ds) finds + +-- Testing function +test :: IO () +test = do + let n = 10 + let unions = [(0, 1), (1, 2), (3, 4), (4, 5), (6, 7), (8, 9), (0, 5), (6, 9)] + let finds = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] + let result = example n unions finds + print result + +main :: IO () +main = test From 1d74377d422122ee7e31bdae9a17331dc45d1fb7 Mon Sep 17 00:00:00 2001 From: Ramy-Badr-Ahmed Date: Sun, 25 Aug 2024 11:13:22 +0200 Subject: [PATCH 02/16] Added Stack Data Structure --- DIRECTORY.md | 1 + src/DataStructures/Stack.hs | 63 +++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 src/DataStructures/Stack.hs diff --git a/DIRECTORY.md b/DIRECTORY.md index ccacd62..7e0936e 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -20,6 +20,7 @@ * Datastructures * [Maxheap](https://github.com/TheAlgorithms/Haskell/blob/master/src/DataStructures/MaxHeap.hs) * [Disjointsets](https://github.com/TheAlgorithms/Haskell/blob/master/src/DataStructures/DisjointSets.hs) + * [Stack](https://github.com/TheAlgorithms/Haskell/blob/master/src/DataStructures/Stack.hs) * Graph * [Dfs](https://github.com/TheAlgorithms/Haskell/blob/master/src/Graph/Dfs.hs) * [Directedgraph](https://github.com/TheAlgorithms/Haskell/blob/master/src/Graph/DirectedGraph.hs) diff --git a/src/DataStructures/Stack.hs b/src/DataStructures/Stack.hs new file mode 100644 index 0000000..a378330 --- /dev/null +++ b/src/DataStructures/Stack.hs @@ -0,0 +1,63 @@ +import Data.Array.ST +import Control.Monad.ST +import Data.STRef + +type Stack s a = (STArray s Int a, STRef s Int) + +-- Create a new stack +newStack :: Int -> ST s (Stack s a) +newStack size = do + arr <- newArray_ (0, size - 1) + topRef <- newSTRef (-1) + return (arr, topRef) + +-- Push an element onto the stack +push :: Stack s a -> a -> ST s () +push (arr, topRef) x = do + top <- readSTRef topRef + let newTop = top + 1 + writeArray arr newTop x + writeSTRef topRef newTop + +-- Pop an element from the stack +pop :: Stack s a -> ST s (Maybe a) +pop (arr, topRef) = do + top <- readSTRef topRef + if top < 0 + then return Nothing + else do + x <- readArray arr top + writeSTRef topRef (top - 1) + return (Just x) + +-- Peek at the top element of the stack +peek :: Stack s a -> ST s (Maybe a) +peek (arr, topRef) = do + top <- readSTRef topRef + if top < 0 + then return Nothing + else Just <$> readArray arr top + +-- Check if the stack is empty +isEmpty :: Stack s a -> ST s Bool +isEmpty (_, topRef) = do + top <- readSTRef topRef + return (top == -1) + +-- Example usage and testing function +testStack :: [Int] -> ([Maybe Int], Bool, Bool) +testStack xs = runST $ do + stack <- newStack (length xs) + mapM_ (push stack) xs + emptyBefore <- isEmpty stack + result <- mapM (\_ -> pop stack) xs + emptyAfter <- isEmpty stack + return (result, emptyBefore, emptyAfter) + +main :: IO () +main = do + let input = [1, 2, 3, 4, 5] + let (result, emptyBefore, emptyAfter) = testStack input + print result -- Expected output: [Just 5, Just 4, Just 3, Just 2, Just 1] + print emptyBefore -- Expected output: False + print emptyAfter -- Expected output: True From 1dc4592fe013e242c4433cf0d9749f81ee9ba997 Mon Sep 17 00:00:00 2001 From: Ramy-Badr-Ahmed Date: Sun, 25 Aug 2024 11:31:28 +0200 Subject: [PATCH 03/16] Added Queue Data Structure --- DIRECTORY.md | 1 + src/DataStructures/Queue.hs | 63 +++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 src/DataStructures/Queue.hs diff --git a/DIRECTORY.md b/DIRECTORY.md index 7e0936e..a13be74 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -21,6 +21,7 @@ * [Maxheap](https://github.com/TheAlgorithms/Haskell/blob/master/src/DataStructures/MaxHeap.hs) * [Disjointsets](https://github.com/TheAlgorithms/Haskell/blob/master/src/DataStructures/DisjointSets.hs) * [Stack](https://github.com/TheAlgorithms/Haskell/blob/master/src/DataStructures/Stack.hs) + * [Queue](https://github.com/TheAlgorithms/Haskell/blob/master/src/DataStructures/Queue.hs) * Graph * [Dfs](https://github.com/TheAlgorithms/Haskell/blob/master/src/Graph/Dfs.hs) * [Directedgraph](https://github.com/TheAlgorithms/Haskell/blob/master/src/Graph/DirectedGraph.hs) diff --git a/src/DataStructures/Queue.hs b/src/DataStructures/Queue.hs new file mode 100644 index 0000000..610ca0e --- /dev/null +++ b/src/DataStructures/Queue.hs @@ -0,0 +1,63 @@ +import Data.Array.ST +import Control.Monad.ST +import Data.STRef + +-- Queue data structure represented using two indices (front, rear) and an array +data Queue s a = Queue { + front :: STRef s Int, + rear :: STRef s Int, + array :: STArray s Int (Maybe a) +} + +-- Initialize a new queue with a given size +newQueue :: Int -> ST s (Queue s a) +newQueue size = do + front <- newSTRef 0 + rear <- newSTRef 0 + array <- newArray (0, size-1) Nothing + return $ Queue front rear array + +-- Enqueue an element +enqueue :: Queue s a -> a -> ST s () +enqueue q x = do + r <- readSTRef (rear q) + writeArray (array q) r (Just x) + writeSTRef (rear q) (r + 1) + +-- Dequeue an element +dequeue :: Queue s a -> ST s (Maybe a) +dequeue q = do + f <- readSTRef (front q) + r <- readSTRef (rear q) + if f == r + then return Nothing -- Queue is empty + else do + x <- readArray (array q) f + writeSTRef (front q) (f + 1) + return x + +-- Check if the queue is empty +isEmptyQueue :: Queue s a -> ST s Bool +isEmptyQueue q = do + f <- readSTRef (front q) + r <- readSTRef (rear q) + return (f == r) + +-- Testing function +testQueue :: [a] -> ([Maybe a], Bool, Bool) +testQueue xs = runST $ do + queue <- newQueue (length xs) + mapM_ (enqueue queue) xs + emptyBefore <- isEmptyQueue queue + result <- mapM (\_ -> dequeue queue) xs + emptyAfter <- isEmptyQueue queue + return (result, emptyBefore, emptyAfter) + +-- Main function +main :: IO () +main = do + let input = [1, 2, 3, 4, 5] + let (result, emptyBefore, emptyAfter) = testQueue input + print result -- Expected output: [Just 1, Just 2, Just 3, Just 4, Just 5] + print emptyBefore -- Expected output: False + print emptyAfter -- Expected output: True From 22bc56423687c619b71728bcd1b450ad94281813 Mon Sep 17 00:00:00 2001 From: Ramy-Badr-Ahmed Date: Wed, 11 Sep 2024 19:44:08 +0200 Subject: [PATCH 04/16] Actions Test on Stack.hs --- src/DataStructures/Stack.hs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/DataStructures/Stack.hs b/src/DataStructures/Stack.hs index a378330..acbe99a 100644 --- a/src/DataStructures/Stack.hs +++ b/src/DataStructures/Stack.hs @@ -58,6 +58,6 @@ main :: IO () main = do let input = [1, 2, 3, 4, 5] let (result, emptyBefore, emptyAfter) = testStack input - print result -- Expected output: [Just 5, Just 4, Just 3, Just 2, Just 1] - print emptyBefore -- Expected output: False - print emptyAfter -- Expected output: True + print result -- Expected output: [Just 5, Just 4, Just 3, Just 2, Just 1] + print emptyBefore -- Expected output: False + print emptyAfter -- Expected output: True From cc8f10b8b5da8be93199c7f61df0f78e528f4f74 Mon Sep 17 00:00:00 2001 From: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Date: Wed, 11 Sep 2024 17:44:42 +0000 Subject: [PATCH 05/16] updating DIRECTORY.md --- DIRECTORY.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DIRECTORY.md b/DIRECTORY.md index a13be74..4063abd 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -18,10 +18,10 @@ * [Binarysearchtree](https://github.com/TheAlgorithms/Haskell/blob/master/src/BinaryTree/BinarySearchTree.hs) * [Binarytree](https://github.com/TheAlgorithms/Haskell/blob/master/src/BinaryTree/BinaryTree.hs) * Datastructures - * [Maxheap](https://github.com/TheAlgorithms/Haskell/blob/master/src/DataStructures/MaxHeap.hs) * [Disjointsets](https://github.com/TheAlgorithms/Haskell/blob/master/src/DataStructures/DisjointSets.hs) - * [Stack](https://github.com/TheAlgorithms/Haskell/blob/master/src/DataStructures/Stack.hs) + * [Maxheap](https://github.com/TheAlgorithms/Haskell/blob/master/src/DataStructures/MaxHeap.hs) * [Queue](https://github.com/TheAlgorithms/Haskell/blob/master/src/DataStructures/Queue.hs) + * [Stack](https://github.com/TheAlgorithms/Haskell/blob/master/src/DataStructures/Stack.hs) * Graph * [Dfs](https://github.com/TheAlgorithms/Haskell/blob/master/src/Graph/Dfs.hs) * [Directedgraph](https://github.com/TheAlgorithms/Haskell/blob/master/src/Graph/DirectedGraph.hs) From f2c08a71deaf22563325bd645f63536aeac2b584 Mon Sep 17 00:00:00 2001 From: Ramy-Badr-Ahmed Date: Wed, 11 Sep 2024 20:13:52 +0200 Subject: [PATCH 06/16] add module on top - Actions-part1 --- src/DataStructures/DisjointSets.hs | 2 ++ src/DataStructures/Queue.hs | 2 ++ src/DataStructures/Stack.hs | 2 ++ 3 files changed, 6 insertions(+) diff --git a/src/DataStructures/DisjointSets.hs b/src/DataStructures/DisjointSets.hs index 434ba2a..9c801ad 100644 --- a/src/DataStructures/DisjointSets.hs +++ b/src/DataStructures/DisjointSets.hs @@ -1,3 +1,5 @@ +module DataStructures.DisjointSets where + import Data.Array.ST import Control.Monad.ST import Data.STRef diff --git a/src/DataStructures/Queue.hs b/src/DataStructures/Queue.hs index 610ca0e..f36be1a 100644 --- a/src/DataStructures/Queue.hs +++ b/src/DataStructures/Queue.hs @@ -1,3 +1,5 @@ +module DataStructures.Queue where + import Data.Array.ST import Control.Monad.ST import Data.STRef diff --git a/src/DataStructures/Stack.hs b/src/DataStructures/Stack.hs index acbe99a..5d0f8a9 100644 --- a/src/DataStructures/Stack.hs +++ b/src/DataStructures/Stack.hs @@ -1,3 +1,5 @@ +module DataStructures.Stack where + import Data.Array.ST import Control.Monad.ST import Data.STRef From 06f175a9be54aeaed53a8f56c7cf57ee510dd406 Mon Sep 17 00:00:00 2001 From: Ramy-Badr-Ahmed Date: Wed, 11 Sep 2024 20:23:27 +0200 Subject: [PATCH 07/16] CI-Stack-part-2 --- src/DataStructures/DisjointSets.hs | 14 +------------- src/DataStructures/Queue.hs | 9 --------- src/DataStructures/Stack.hs | 10 +--------- 3 files changed, 2 insertions(+), 31 deletions(-) diff --git a/src/DataStructures/DisjointSets.hs b/src/DataStructures/DisjointSets.hs index 9c801ad..c21aad2 100644 --- a/src/DataStructures/DisjointSets.hs +++ b/src/DataStructures/DisjointSets.hs @@ -51,16 +51,4 @@ example :: Int -> [(Node, Node)] -> [Node] -> [Node] example n unions finds = runST $ do ds <- makeSet n mapM_ (uncurry $ unionSet ds) unions - mapM (findSet ds) finds - --- Testing function -test :: IO () -test = do - let n = 10 - let unions = [(0, 1), (1, 2), (3, 4), (4, 5), (6, 7), (8, 9), (0, 5), (6, 9)] - let finds = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] - let result = example n unions finds - print result - -main :: IO () -main = test + mapM (findSet ds) finds \ No newline at end of file diff --git a/src/DataStructures/Queue.hs b/src/DataStructures/Queue.hs index f36be1a..29dfb56 100644 --- a/src/DataStructures/Queue.hs +++ b/src/DataStructures/Queue.hs @@ -54,12 +54,3 @@ testQueue xs = runST $ do result <- mapM (\_ -> dequeue queue) xs emptyAfter <- isEmptyQueue queue return (result, emptyBefore, emptyAfter) - --- Main function -main :: IO () -main = do - let input = [1, 2, 3, 4, 5] - let (result, emptyBefore, emptyAfter) = testQueue input - print result -- Expected output: [Just 1, Just 2, Just 3, Just 4, Just 5] - print emptyBefore -- Expected output: False - print emptyAfter -- Expected output: True diff --git a/src/DataStructures/Stack.hs b/src/DataStructures/Stack.hs index 5d0f8a9..1a88e04 100644 --- a/src/DataStructures/Stack.hs +++ b/src/DataStructures/Stack.hs @@ -54,12 +54,4 @@ testStack xs = runST $ do emptyBefore <- isEmpty stack result <- mapM (\_ -> pop stack) xs emptyAfter <- isEmpty stack - return (result, emptyBefore, emptyAfter) - -main :: IO () -main = do - let input = [1, 2, 3, 4, 5] - let (result, emptyBefore, emptyAfter) = testStack input - print result -- Expected output: [Just 5, Just 4, Just 3, Just 2, Just 1] - print emptyBefore -- Expected output: False - print emptyAfter -- Expected output: True + return (result, emptyBefore, emptyAfter) \ No newline at end of file From e60341b4e42ba6cb6b2e279e0939ac3f370bec2a Mon Sep 17 00:00:00 2001 From: Ramy-Badr-Ahmed Date: Wed, 11 Sep 2024 20:34:04 +0200 Subject: [PATCH 08/16] updating package.yaml. CI-Stack-part-3 --- package.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/package.yaml b/package.yaml index 581948d..e9c2dce 100644 --- a/package.yaml +++ b/package.yaml @@ -23,6 +23,7 @@ library: - containers - vector - vector-algorithms + - array source-dirs: src tests: @@ -35,6 +36,7 @@ tests: - hspec - QuickCheck - containers + - array ghc-options: - -rtsopts - -threaded From 0c545ab3a3f261fe055afeee13533818ae2b29e2 Mon Sep 17 00:00:00 2001 From: Ramy-Badr-Ahmed Date: Wed, 11 Sep 2024 20:55:37 +0200 Subject: [PATCH 09/16] Added Main directory and executable section to package.yaml --- package.yaml | 22 ++++++++++++++++++++++ src/Main/DisjointSetsMain.hs | 11 +++++++++++ src/Main/QueueMain.hs | 11 +++++++++++ src/Main/StackMain.hs | 11 +++++++++++ 4 files changed, 55 insertions(+) create mode 100644 src/Main/DisjointSetsMain.hs create mode 100644 src/Main/QueueMain.hs create mode 100644 src/Main/StackMain.hs diff --git a/package.yaml b/package.yaml index e9c2dce..5d9d337 100644 --- a/package.yaml +++ b/package.yaml @@ -26,6 +26,28 @@ library: - array source-dirs: src +executables: + stack-exe: + main: Main/StackMain.hs + source-dirs: src/Main + dependencies: + - base + - DataStructures + + queue-exe: + main: Main/QueueMain.hs + source-dirs: src/Main + dependencies: + - base + - DataStructures + + disjoint-sets-exe: + main: Main/DisjointSetsMain.hs + source-dirs: src/Main + dependencies: + - base + - DataStructures + tests: Haskell-test-suite: source-dirs: specs diff --git a/src/Main/DisjointSetsMain.hs b/src/Main/DisjointSetsMain.hs new file mode 100644 index 0000000..df3d4b3 --- /dev/null +++ b/src/Main/DisjointSetsMain.hs @@ -0,0 +1,11 @@ +module Main where + +import DataStructures.DisjointSets + +main :: IO () +main = do + let n = 10 + let unions = [(0, 1), (1, 2), (3, 4), (4, 5), (6, 7), (8, 9), (0, 5), (6, 9)] + let finds = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] + let result = example n unions finds + print result diff --git a/src/Main/QueueMain.hs b/src/Main/QueueMain.hs new file mode 100644 index 0000000..58c8a96 --- /dev/null +++ b/src/Main/QueueMain.hs @@ -0,0 +1,11 @@ +module Main where + +import DataStructures.Queue + +main :: IO () +main = do + let input = [1, 2, 3, 4, 5] + let (result, emptyBefore, emptyAfter) = testQueue input + print result -- Expected output: [Just 1, Just 2, Just 3, Just 4, Just 5] + print emptyBefore -- Expected output: False + print emptyAfter -- Expected output: True diff --git a/src/Main/StackMain.hs b/src/Main/StackMain.hs new file mode 100644 index 0000000..efb8ac1 --- /dev/null +++ b/src/Main/StackMain.hs @@ -0,0 +1,11 @@ +module Main where + +import DataStructures.Stack + +main :: IO () +main = do + let input = [1, 2, 3, 4, 5] + let (result, emptyBefore, emptyAfter) = testStack input + print result -- Expected output: [Just 5, Just 4, Just 3, Just 2, Just 1] + print emptyBefore -- Expected output: False + print emptyAfter -- Expected output: True From 64aababcb5c551275dc65c173eaefffe6ed9d171 Mon Sep 17 00:00:00 2001 From: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Date: Wed, 11 Sep 2024 18:55:59 +0000 Subject: [PATCH 10/16] updating DIRECTORY.md --- DIRECTORY.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/DIRECTORY.md b/DIRECTORY.md index 4063abd..0100166 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -26,6 +26,10 @@ * [Dfs](https://github.com/TheAlgorithms/Haskell/blob/master/src/Graph/Dfs.hs) * [Directedgraph](https://github.com/TheAlgorithms/Haskell/blob/master/src/Graph/DirectedGraph.hs) * [Haskellalgorithms](https://github.com/TheAlgorithms/Haskell/blob/master/src/HaskellAlgorithms.hs) + * Main + * [Disjointsetsmain](https://github.com/TheAlgorithms/Haskell/blob/master/src/Main/DisjointSetsMain.hs) + * [Queuemain](https://github.com/TheAlgorithms/Haskell/blob/master/src/Main/QueueMain.hs) + * [Stackmain](https://github.com/TheAlgorithms/Haskell/blob/master/src/Main/StackMain.hs) * Maths * [Factorial](https://github.com/TheAlgorithms/Haskell/blob/master/src/Maths/Factorial.hs) * [Fibonacci](https://github.com/TheAlgorithms/Haskell/blob/master/src/Maths/Fibonacci.hs) From f67fc802ea33cd7ddbd14ecd2a4ccf7e949f607a Mon Sep 17 00:00:00 2001 From: Ramy-Badr-Ahmed Date: Wed, 11 Sep 2024 21:04:25 +0200 Subject: [PATCH 11/16] modifying executable section inpackage.yaml --- package.yaml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/package.yaml b/package.yaml index 5d9d337..6998c49 100644 --- a/package.yaml +++ b/package.yaml @@ -28,22 +28,22 @@ library: executables: stack-exe: - main: Main/StackMain.hs - source-dirs: src/Main + main: src/Main/StackMain.hs + source-dirs: src dependencies: - base - DataStructures queue-exe: - main: Main/QueueMain.hs - source-dirs: src/Main + main: src/Main/QueueMain.hs + source-dirs: src dependencies: - base - DataStructures disjoint-sets-exe: - main: Main/DisjointSetsMain.hs - source-dirs: src/Main + main: src/Main/DisjointSetsMain.hs + source-dirs: src dependencies: - base - DataStructures From 9562d9f282f2d27955a132fe0c6484450772eb53 Mon Sep 17 00:00:00 2001 From: Ramy-Badr-Ahmed Date: Wed, 11 Sep 2024 21:24:58 +0200 Subject: [PATCH 12/16] moved main files, removed executable section --- package.yaml | 22 ------------------- .../DisjointSetsMain.hs | 0 src/{Main => DataStructures}/QueueMain.hs | 0 src/{Main => DataStructures}/StackMain.hs | 0 4 files changed, 22 deletions(-) rename src/{Main => DataStructures}/DisjointSetsMain.hs (100%) rename src/{Main => DataStructures}/QueueMain.hs (100%) rename src/{Main => DataStructures}/StackMain.hs (100%) diff --git a/package.yaml b/package.yaml index 6998c49..e9c2dce 100644 --- a/package.yaml +++ b/package.yaml @@ -26,28 +26,6 @@ library: - array source-dirs: src -executables: - stack-exe: - main: src/Main/StackMain.hs - source-dirs: src - dependencies: - - base - - DataStructures - - queue-exe: - main: src/Main/QueueMain.hs - source-dirs: src - dependencies: - - base - - DataStructures - - disjoint-sets-exe: - main: src/Main/DisjointSetsMain.hs - source-dirs: src - dependencies: - - base - - DataStructures - tests: Haskell-test-suite: source-dirs: specs diff --git a/src/Main/DisjointSetsMain.hs b/src/DataStructures/DisjointSetsMain.hs similarity index 100% rename from src/Main/DisjointSetsMain.hs rename to src/DataStructures/DisjointSetsMain.hs diff --git a/src/Main/QueueMain.hs b/src/DataStructures/QueueMain.hs similarity index 100% rename from src/Main/QueueMain.hs rename to src/DataStructures/QueueMain.hs diff --git a/src/Main/StackMain.hs b/src/DataStructures/StackMain.hs similarity index 100% rename from src/Main/StackMain.hs rename to src/DataStructures/StackMain.hs From 478a835c48b6ff391bfcf17e9964c8e9d6726834 Mon Sep 17 00:00:00 2001 From: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Date: Wed, 11 Sep 2024 19:25:15 +0000 Subject: [PATCH 13/16] updating DIRECTORY.md --- DIRECTORY.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/DIRECTORY.md b/DIRECTORY.md index 0100166..a559f40 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -19,17 +19,16 @@ * [Binarytree](https://github.com/TheAlgorithms/Haskell/blob/master/src/BinaryTree/BinaryTree.hs) * Datastructures * [Disjointsets](https://github.com/TheAlgorithms/Haskell/blob/master/src/DataStructures/DisjointSets.hs) + * [Disjointsetsmain](https://github.com/TheAlgorithms/Haskell/blob/master/src/DataStructures/DisjointSetsMain.hs) * [Maxheap](https://github.com/TheAlgorithms/Haskell/blob/master/src/DataStructures/MaxHeap.hs) * [Queue](https://github.com/TheAlgorithms/Haskell/blob/master/src/DataStructures/Queue.hs) + * [Queuemain](https://github.com/TheAlgorithms/Haskell/blob/master/src/DataStructures/QueueMain.hs) * [Stack](https://github.com/TheAlgorithms/Haskell/blob/master/src/DataStructures/Stack.hs) + * [Stackmain](https://github.com/TheAlgorithms/Haskell/blob/master/src/DataStructures/StackMain.hs) * Graph * [Dfs](https://github.com/TheAlgorithms/Haskell/blob/master/src/Graph/Dfs.hs) * [Directedgraph](https://github.com/TheAlgorithms/Haskell/blob/master/src/Graph/DirectedGraph.hs) * [Haskellalgorithms](https://github.com/TheAlgorithms/Haskell/blob/master/src/HaskellAlgorithms.hs) - * Main - * [Disjointsetsmain](https://github.com/TheAlgorithms/Haskell/blob/master/src/Main/DisjointSetsMain.hs) - * [Queuemain](https://github.com/TheAlgorithms/Haskell/blob/master/src/Main/QueueMain.hs) - * [Stackmain](https://github.com/TheAlgorithms/Haskell/blob/master/src/Main/StackMain.hs) * Maths * [Factorial](https://github.com/TheAlgorithms/Haskell/blob/master/src/Maths/Factorial.hs) * [Fibonacci](https://github.com/TheAlgorithms/Haskell/blob/master/src/Maths/Fibonacci.hs) From 788e459e36c492debfb4657121f4b66c5693a3cb Mon Sep 17 00:00:00 2001 From: Ramy-Badr-Ahmed Date: Wed, 11 Sep 2024 21:29:09 +0200 Subject: [PATCH 14/16] correct module --- src/DataStructures/DisjointSetsMain.hs | 2 +- src/DataStructures/QueueMain.hs | 2 +- src/DataStructures/StackMain.hs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/DataStructures/DisjointSetsMain.hs b/src/DataStructures/DisjointSetsMain.hs index df3d4b3..69b1d1b 100644 --- a/src/DataStructures/DisjointSetsMain.hs +++ b/src/DataStructures/DisjointSetsMain.hs @@ -1,4 +1,4 @@ -module Main where +module DataStructures.DisjointSetsMain where import DataStructures.DisjointSets diff --git a/src/DataStructures/QueueMain.hs b/src/DataStructures/QueueMain.hs index 58c8a96..be72e30 100644 --- a/src/DataStructures/QueueMain.hs +++ b/src/DataStructures/QueueMain.hs @@ -1,4 +1,4 @@ -module Main where +module DataStructures.QueueMain where import DataStructures.Queue diff --git a/src/DataStructures/StackMain.hs b/src/DataStructures/StackMain.hs index efb8ac1..a8c78ae 100644 --- a/src/DataStructures/StackMain.hs +++ b/src/DataStructures/StackMain.hs @@ -1,4 +1,4 @@ -module Main where +module DataStructures.StackMain where import DataStructures.Stack From ce326cbaf9b90c797d06a814c260e24347975d44 Mon Sep 17 00:00:00 2001 From: Ramy <126559907+Ramy-Badr-Ahmed@users.noreply.github.com> Date: Wed, 11 Sep 2024 21:33:17 +0200 Subject: [PATCH 15/16] CI Stack - Passing --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 2ce21d0..156ea68 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ -![CI (Stack)](https://github.com/TheAlgorithms/Haskell/workflows/CI%20(Stack)/badge.svg) +[![CI (Stack)](https://github.com/Ramy-Badr-Ahmed/Haskell-DSA/actions/workflows/CI.yml/badge.svg)](https://github.com/Ramy-Badr-Ahmed/Haskell-DSA/actions/workflows/CI.yml) + # The Algorithms - Haskell Haskell is a general-purpose, statically typed, purely functional programming language with type inference and lazy evaluation. From a9b0e2db199cdc498d69256db54f8d999ef4335c Mon Sep 17 00:00:00 2001 From: Ramy-Badr-Ahmed Date: Sat, 28 Sep 2024 15:25:36 +0200 Subject: [PATCH 16/16] Implemented Disjoint Set, Stack and Queue Data Structures. Added comments to my files in #54. --- src/DataStructures/DisjointSets.hs | 8 ++++++++ src/DataStructures/DisjointSetsMain.hs | 8 ++++++++ src/DataStructures/Queue.hs | 8 ++++++++ src/DataStructures/QueueMain.hs | 8 ++++++++ src/DataStructures/Stack.hs | 8 ++++++++ src/DataStructures/StackMain.hs | 8 ++++++++ 6 files changed, 48 insertions(+) diff --git a/src/DataStructures/DisjointSets.hs b/src/DataStructures/DisjointSets.hs index c21aad2..dfa1d26 100644 --- a/src/DataStructures/DisjointSets.hs +++ b/src/DataStructures/DisjointSets.hs @@ -1,3 +1,11 @@ +{-| +Created by: Ramy-Badr-Ahmed (https://github.com/Ramy-Badr-Ahmed) in Pull Request: #54 +https://github.com/TheAlgorithms/Haskell/pull/54 + +Please mention me (@Ramy-Badr-Ahmed) in any issue or pull request addressing bugs/corrections to this file. +Thank you! +-} + module DataStructures.DisjointSets where import Data.Array.ST diff --git a/src/DataStructures/DisjointSetsMain.hs b/src/DataStructures/DisjointSetsMain.hs index 69b1d1b..dd62ddf 100644 --- a/src/DataStructures/DisjointSetsMain.hs +++ b/src/DataStructures/DisjointSetsMain.hs @@ -1,3 +1,11 @@ +{-| +Created by: Ramy-Badr-Ahmed (https://github.com/Ramy-Badr-Ahmed) in Pull Request: #54 +https://github.com/TheAlgorithms/Haskell/pull/54 + +Please mention me (@Ramy-Badr-Ahmed) in any issue or pull request addressing bugs/corrections to this file. +Thank you! +-} + module DataStructures.DisjointSetsMain where import DataStructures.DisjointSets diff --git a/src/DataStructures/Queue.hs b/src/DataStructures/Queue.hs index 29dfb56..0780d98 100644 --- a/src/DataStructures/Queue.hs +++ b/src/DataStructures/Queue.hs @@ -1,3 +1,11 @@ +{-| +Created by: Ramy-Badr-Ahmed (https://github.com/Ramy-Badr-Ahmed) in Pull Request: #54 +https://github.com/TheAlgorithms/Haskell/pull/54 + +Please mention me (@Ramy-Badr-Ahmed) in any issue or pull request addressing bugs/corrections to this file. +Thank you! +-} + module DataStructures.Queue where import Data.Array.ST diff --git a/src/DataStructures/QueueMain.hs b/src/DataStructures/QueueMain.hs index be72e30..58a4ad4 100644 --- a/src/DataStructures/QueueMain.hs +++ b/src/DataStructures/QueueMain.hs @@ -1,3 +1,11 @@ +{-| +Created by: Ramy-Badr-Ahmed (https://github.com/Ramy-Badr-Ahmed) in Pull Request: #54 +https://github.com/TheAlgorithms/Haskell/pull/54 + +Please mention me (@Ramy-Badr-Ahmed) in any issue or pull request addressing bugs/corrections to this file. +Thank you! +-} + module DataStructures.QueueMain where import DataStructures.Queue diff --git a/src/DataStructures/Stack.hs b/src/DataStructures/Stack.hs index 1a88e04..6c8fb94 100644 --- a/src/DataStructures/Stack.hs +++ b/src/DataStructures/Stack.hs @@ -1,3 +1,11 @@ +{-| +Created by: Ramy-Badr-Ahmed (https://github.com/Ramy-Badr-Ahmed) in Pull Request: #54 +https://github.com/TheAlgorithms/Haskell/pull/54 + +Please mention me (@Ramy-Badr-Ahmed) in any issue or pull request addressing bugs/corrections to this file. +Thank you! +-} + module DataStructures.Stack where import Data.Array.ST diff --git a/src/DataStructures/StackMain.hs b/src/DataStructures/StackMain.hs index a8c78ae..bdb0727 100644 --- a/src/DataStructures/StackMain.hs +++ b/src/DataStructures/StackMain.hs @@ -1,3 +1,11 @@ +{-| +Created by: Ramy-Badr-Ahmed (https://github.com/Ramy-Badr-Ahmed) in Pull Request: #54 +https://github.com/TheAlgorithms/Haskell/pull/54 + +Please mention me (@Ramy-Badr-Ahmed) in any issue or pull request addressing bugs/corrections to this file. +Thank you! +-} + module DataStructures.StackMain where import DataStructures.Stack