asked 226k views
0 votes
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"]

asked
User Rocco
by
7.6k points

2 Answers

5 votes

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)

Step-by-step explanation:

I got a 100%

answered
User Oscfri
by
7.8k points
3 votes

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)

Step-by-step explanation:

I hope this helps you!

answered
User Adam Caviness
by
8.3k points

Related questions