English

Millions of computer science students have taken a course on algorithms and data structures, typically the second course after the initial one introducing programming.

Advertisements
Advertisements

Question

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:

  1. In recursive function
  2. When function is called.
  3. Expression conversion such as - Infix to Postfix,
  4. 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. ______ (N)          # Statement 1
# Function Calling
Country=[]
C=['lndian', 'US.N, 'UK', 'Canada', 'Sri Lanka']
for i in range (0, len(C), _______) :     # Statement 2
push (Country, C[i])
      print (Country)
Required Output:
['Indian', 'UK', 'Shri 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
Underflow

Fill the above statement based on given question:

Identify the suitable code for the blank of Statement 1.

Options

  • .append()

  • .insert()

  • .extent()

  • .append(len(Country), N)

MCQ
Advertisements

Solution

.append()

shaalaa.com
  Is there an error in this question or solution?
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×