0% found this document useful (0 votes)
13 views2 pages

02-Stack 1

The document outlines an assignment involving the implementation of data structures in Python, specifically a stack and a queue. It includes five problems: creating a stack class with various methods, checking for balanced parentheses using a stack, evaluating postfix expressions with a stack-based calculator, implementing a queue class, and creating a circular queue with memory efficiency. Each problem provides examples to illustrate the expected input and output.

Uploaded by

xj4gh5fm5d
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views2 pages

02-Stack 1

The document outlines an assignment involving the implementation of data structures in Python, specifically a stack and a queue. It includes five problems: creating a stack class with various methods, checking for balanced parentheses using a stack, evaluating postfix expressions with a stack-based calculator, implementing a queue class, and creating a circular queue with memory efficiency. Each problem provides examples to illustrate the expected input and output.

Uploaded by

xj4gh5fm5d
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Assignment # 2

Stack & Queue


Problem 1: Implement a stack class in Python with the following methods:

• push(element): Adds an element to the top


• pop(): Removes and returns the top element
• peek(): Returns the top element without removing it
• isEmpty(): Checks if the stack is empty
• size(): Returns the number of elements

Problem 2: Write a function that uses a stack to check if a string containing


parentheses (), brackets [], and braces {} is balanced.

Example:

• Input: "({[]})" → Output: True


• Input: "({[)]}" → Output: False

Problem 3: Implement a stack-based calculator that evaluates postfix (Reverse Polish


Notation) expressions.

Example:

• Input: "3 4 + 2 *" → Output: 14


• Input: "5 1 2 + 4 * + 3 -" → Output: 14

Problem 4: Implement a queue class with the following methods:

• enqueue(element): Adds an element to the rear


• dequeue(): Removes and returns the front element
• front(): Returns the front element without removing it
• isEmpty(): Checks if the queue is empty
• size(): Returns the number of elements

Problem 5: Implement a circular queue with fixed capacity that efficiently utilizes
memory:

• Handle wrap-around conditions


• Implement proper full/empty checks
• Include a method to display all elements

You might also like