CodeTestValidate

No installations needed! Write Python directly in your browser and get instant feedback with our smart validation system.

Challenge # 6

Implement Stack and Queue Using Lists

Objective

Understand how stack (LIFO) and queue (FIFO) structures work by implementing them using lists.

Instructions

  • Create a class Stack and a class Queue.

  • Each class should implement basic operations: push, pop, and is_empty for Stack; enqueue, dequeue, and is_empty for Queue.

  • Use only built-in Python list operations.

  • Do not use collections.deque or other external libraries.

Constraints:
Do not use input(). • Do not use any external libraries like `collections` or `queue`. • Use only list methods like `append()` and `pop()`.
Exemple IO

Input: s = Stack()s.push(1)s.push(2)print(s.pop())

Output: 2

Input: q = Queue()q.enqueue(1)q.enqueue(2)print(q.dequeue())

Output: 1

Try It Online!

Output:

Validate Your Results

Get your code reviewed and validated to understand what you did right and where you can improve.

Previous challengeCount Words in a Sentence (Ignore Punctuation)Next challengeDefine a Rectangle Class with Area and Perimeter
Loading...