Millions of computer science students have taken a course on algorithms and data structures, typically the second course after the initial one introducing programming. One of the basic data structures in such a course is the stack. The stack has a special place in the emergence of computing as a science, as argued by Michael Mahoney, the pioneer of the history of the theory of computing. The Stack can be used in many computer applications, few are given below:
a) In recursive function
b) When function is called.
c) Expression conversion such as – Infix to Postfix, Infix to Prefix, Postfix to Infix, Prefix to Infix.
In Stack, insertion operation is known as Push whereas deletion operation is known as Pop.
Code – 1
def push(Country,N):
Country._________(len(Country),N)) #Statement 1
#Function Calling
Country=[ ]
C=['Indian', 'USA', 'UK', 'Canada', 'Sri Lanka']
for i in range(0,len(C),________): #Statement
2 push(Country,C[i])
print(Country)
Required Output:
['Indian', 'UK', 'Sri Lanka']
Code - 2
def pop(Country):
if __________: #Statement 3
return "Under flow" else: return Country.________() #Statement 4 #
Function Calling
for i in range(len(Country)+1): print(_______) #Statement 5
Required Output:
Sri Lanka
UK
India
Under flow
Fill the above statement based on given questions:
i. Identify the suitable code for the blank of statement 1.
a. .append()
b. .insert()
c. .extend()
d. .append(len(Country),N)
ii. Fill the statement 2, to insert the alternate element from Country list.
a. 3
b. 0
c. -1
d. 2
iii. Fill the statement 3, to check the stack is empty.
a. Country=[]
b. Country.isEmpty()
c. len(country)==0 d. No of the above
iv. Fill the statement 4, to delete an element from the stack.
a. pop(1)
b. pop()
c. del country[1]
d. Country.delete(1)
v. Fill the statement 5, to call the pop function.
a. pop(C)
b. pop(Country)
c. call pop(Country)
d. def pop(Country)