Sobes.tech
Junior

Describe the main operations with data structures such as stack and queue.

sobes.tech AI

Answer from AI

  • Stack:

    • push(item): Adds the element item to the top of the stack.
    • pop(): Removes and returns the element from the top of the stack. If the stack is empty, it usually raises an error (or returns a special value depending on the implementation).
    • peek(): Returns the element at the top of the stack without removing it. If the stack is empty, it usually raises an error.
    • is_empty(): Checks if the stack is empty. Returns a boolean value (True or False).
    • size(): Returns the number of elements in the stack.
  • Queue:

    • enqueue(item): Adds the element item to the end of the queue.
    • dequeue(): Removes and returns the element from the front of the queue. If the queue is empty, it usually raises an error.
    • front(): Returns the element at the front of the queue without removing it. If the queue is empty, it usually raises an error.
    • is_empty(): Checks if the queue is empty. Returns a boolean value.
    • size(): Returns the number of elements in the queue.