def element(x):
first_element = x[0]
for i in range(0, len(x)):
if first_element <= x[i]:
pass
else:
first_element = x[i]
return first_element
def ascending(y):
new_list = []
old_list = y
for i in range(0,len(y)):
small = element(y)
new_list.append(small)
old_list.remove(small)
return new_list[-2]
#print ascending([5,25,41,8,-35,-63,-0.25,21])
Program 2:
__author__ = 'valli_000'
def bubblesortdescending(list):
length = len(list)
count = length-1
while count > 0:
for i in range(length-1):
if list[i] <= list[i+1]:
temp = list[i]
list[i] = list[i+1]
list[i+1]=temp
#print list
else:
pass
count= count - 1
return list
def bubblesortascending(list):
length = len(list)
count = length-1
while count > 0:
for i in range(length-1):
if list[i] <= list[i+1]:
pass
#print list
else:
temp = list[i]
list[i] = list[i+1]
list[i+1]=temp
count= count - 1
return list
print bubblesortdescending([119, 1, 9, 7, 3, 10, 13, 15, 8, 12])
print bubblesortascending([119, 1, 9, 7, 3, 10, 13, 15, 8, 12])
first_element = x[0]
for i in range(0, len(x)):
if first_element <= x[i]:
pass
else:
first_element = x[i]
return first_element
def ascending(y):
new_list = []
old_list = y
for i in range(0,len(y)):
small = element(y)
new_list.append(small)
old_list.remove(small)
return new_list[-2]
#print ascending([5,25,41,8,-35,-63,-0.25,21])
Program 2:
__author__ = 'valli_000'
def bubblesortdescending(list):
length = len(list)
count = length-1
while count > 0:
for i in range(length-1):
if list[i] <= list[i+1]:
temp = list[i]
list[i] = list[i+1]
list[i+1]=temp
#print list
else:
pass
count= count - 1
return list
def bubblesortascending(list):
length = len(list)
count = length-1
while count > 0:
for i in range(length-1):
if list[i] <= list[i+1]:
pass
#print list
else:
temp = list[i]
list[i] = list[i+1]
list[i+1]=temp
count= count - 1
return list
print bubblesortdescending([119, 1, 9, 7, 3, 10, 13, 15, 8, 12])
print bubblesortascending([119, 1, 9, 7, 3, 10, 13, 15, 8, 12])
No comments:
Post a Comment