CBSE · 083Class XII · 2025Section C3 marks
Question 30
4 March 2025 · Computer Science (083)
Write the following user-defined functions in Python to perform the specified operations on ClrStack:
(i) push_Clr(ClrStack, new_Clr): This function takes the stack ClrStack and a new record new_Clr as arguments and pushes this new record onto the stack.
(ii) pop_Clr(ClrStack): This function pops the topmost record from the stack and returns it. If the stack is already empty, the function should display the message "Underflow".
(iii) isEmpty(ClrStack): This function checks whether the stack is empty. If the stack is empty, the function should return True, otherwise the function should return False.
Answer
python
def push_Clr(ClrStack, new_Clr):
ClrStack.append(new_Clr)
def pop_Clr(ClrStack):
if len(ClrStack) == 0:
print("Underflow")
else:
return(ClrStack.pop())
def isEmpty(ClrStack):
if len(ClrStack) == 0:
return True
else:
return False