Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented Queue Data Structure #55

Closed

Conversation

Ramy-Badr-Ahmed
Copy link
Member

This PR adds an implementation of the Queue data structure using mutable arrays within the Haskedll ST monad.

The queue supports typical queue operations such as enqueue, dequeue, and checking for emptiness.

Implementation Details:

  • newQueue :: Int -> ST s (Queue s a): Initializes a new queue with a given capacity.
  • enqueue :: Queue s a -> a -> ST s (): Adds an element to the end of the queue.
  • dequeue :: Queue s a -> ST s (Maybe a): Removes an element from the front of the queue. Returns Nothing if the queue is empty.
  • isEmptyQueue :: Queue s a -> ST s Bool: Checks if the queue is empty.

Testing:

A testing function that enqueues a list of elements, then dequeues them, and checks if the queue was empty before and after operations.

  • testQueue :: [a] -> ([Maybe a], Bool, Bool)
  • main :: IO (): tests the queue implementation
  • Input:
    let input = [1, 2, 3, 4, 5]
  • Expected Output
    [Just 1, Just 2, Just 3, Just 4, Just 5]
    False
    True

@Ramy-Badr-Ahmed Ramy-Badr-Ahmed changed the title Implemented Queue Data Structure using Mutable Arrays Implemented Queue Data Structure Aug 25, 2024
Ramy-Badr-Ahmed

This comment was marked as outdated.

@Ramy-Badr-Ahmed

This comment was marked as duplicate.

@Ramy-Badr-Ahmed Ramy-Badr-Ahmed marked this pull request as draft September 11, 2024 19:39
@Ramy-Badr-Ahmed Ramy-Badr-Ahmed deleted the queue-DS branch September 11, 2024 19:41
@Ramy-Badr-Ahmed
Copy link
Member Author

Ramy-Badr-Ahmed commented Sep 11, 2024

Closed it and combined it with #54

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant