Implement a sorting algorithm and sort the vocab array (found below) alphabetically. For this question, do not define or use an explicit swap function (you will revisit this in question 3). Print the vocab array before and after it is sorted. Vocab = [ "Libraries", "Bandwidth", "Hierarchy", "Software", "Firewall", "Cybersecurity","Phishing", "Logic", "Productivity"]

Respuesta :

Answer:

vocab = [ "Libraries", "Bandwidth", "Hierarchy", "Software", "Firewall", "Cybersecurity","Phishing", "Logic", "Productivity"]

print(vocab)

needNextPass = True

k = 1

#list = [x.lower() for x in list]

while k < len(vocab)-1 and needNextPass:

   # List may be sorted and next pass not needed

   needNextPass = False

   for i in range(len(vocab) - k):

       if vocab[i] > vocab[i + 1]:

           # swap list[i] with list[i + 1]

           temp = vocab[i]

           vocab[i] = vocab[i + 1]

           vocab[i + 1] = temp

           needNextPass = True  # Next pass still needed

print(vocab)

Explanation:

I hope this helps you!

Answer:

vocab = ["Libraries", "Bandwidth", "Hierarchy", "Software", "Firewall", "Cybersecurity","Phishing", "Logic", "Productivity"]

print(vocab)

needNextPass=True

k=1

while (k < len(vocab)-1 and needNextPass):

  needNextPass=False

 

  for i in range(len(vocab)-k):

     

      if vocab[i] > vocab[i+1]:

          temp=vocab[i]

          vocab[i]=vocab[i+1]

          vocab[i+1]=temp

          needNextPass=True

         

print(vocab)

Explanation:

I got a 100%

Otras preguntas