Skip to content

Jean D Amour Kubwimana: Implement Data Structures and Algorithms Solutions#106

Open
Jdamour12 wants to merge 8 commits intoPLPAfrica:mainfrom
Jdamour12:jdamour-branch
Open

Jean D Amour Kubwimana: Implement Data Structures and Algorithms Solutions#106
Jdamour12 wants to merge 8 commits intoPLPAfrica:mainfrom
Jdamour12:jdamour-branch

Conversation

@Jdamour12
Copy link

This pull request includes solutions for three data structures and algorithm challenges:

  1. Reverse a String Using a Stack:

    • Implemented a stack-based approach to reverse a string.
    • Function: reverse_string(s: str) -> str
    • Example: reverse_string("hello") returns "olleh"
  2. Queue Implementation Using Two Stacks:

    • Developed a queue class using two stacks for enqueue and dequeue operations.
    • Class: QueueWithStacks
    • Methods:
      • enqueue(x: int): Adds an element to the queue.
      • dequeue() -> int: Removes and returns the front element of the queue.
    • Example:
      q = QueueWithStacks()
      q.enqueue(1)
      q.enqueue(2)
      print(q.dequeue())  # Output: 1
      print(q.dequeue())  # Output: 2
  3. Find the Maximum Element in a Linked List:

    • Implemented a singly linked list with a method to find the maximum element.
    • Class: LinkedList
    • Method: find_max() -> int
    • Example:
      ll = LinkedList()
      ll.append(3)
      ll.append(1)
      ll.append(4)
      ll.append(2)
      print(ll.find_max())  # Output: 4

The implementations include user input prompts and descriptive output messages. The code is well-documented and adheres to best practices for clarity and efficiency.

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

Comments