Exemple #1
0
 def setUpClass(cls):
     super().setUpClass()
     cls.numbers_5 = load_numbers('numbers/5.txt')
     cls.numbers_8 = load_numbers('numbers/8.txt')
     cls.numbers_10k = load_numbers('numbers/10k.txt')
     cls.numbers_1kk = load_numbers('numbers/1kk.txt')
#
#  Algorithms: Sorting and Searching: Selection Sort
#  Python Techdegree
#
#  Created by Dulio Denis on 3/25/19.
#  Copyright (c) 2019 ddApps. All rights reserved.
# ------------------------------------------------
import sys
from load import load_numbers

numbers = load_numbers(sys.argv[1])


# ------------------------------------------------
def selection_sort(values):
    # We'll create an empty list that will hold all our sorted values.
    sorted_list = []
    print("%-25s %-25s" % (values, sorted_list))

    # We'll loop once for each value in the list.
    for i in range(0, len(values)):
        # We call a function named index_of_min that find the minimum
        # value in the unsorted list and return its index.
        index_to_move = index_of_min(values)

        # Then we call the "pop" method on the list, and pass it the
        # index of the minimum value. pop will remove that item from the
        # list and return it. We then add that value at the end of the
        # sorted list.
        sorted_list.append(values.pop(index_to_move))
        print("%-25s %-25s" % (values, sorted_list))
Exemple #3
0
#------------------// sort lkinked list \\-------------------------------------
print("\n--------// sort lkinked list \\\\-------")
l = Linked_list()
l.add(20)
l.add(30)
l.add(10)
l.add(5)
l.add(25)
l.add(40)
print(l)
sorted_link_list = Linked_list_sortition.sort_linked_list(l)
print(sorted_link_list)

#------------------// bogo sort \\-------------------------------------
print("\n-----------//bogo sort \\\\ ----------------")
alist1 = load_numbers("Data_Structures/Files/numers.txt")
StartTime = time.perf_counter_ns()
sorted_bogo = Sort.bogo_sort(alist1)
EndTime = time.perf_counter_ns()
print(f"sort_list:{sorted_bogo} \ntime of monitor: {(EndTime-StartTime)} ")
#------------------// selection sort \\--------------------------------------
print("\n-----------// selection sort \\\\ ----------------")
StartTime = time.perf_counter_ns()
sorted_selection = Sort.selection_sort(alist)
EndTime = time.perf_counter_ns()
print(
    f"sort_list:{sorted_selection} \ntime of monitor: {(EndTime-StartTime)} ")

#-----------------// quick sort \\--------------------------------------------
print("\n----------// quick sort\\\\------------------------ ")
StartTime = time.perf_counter_ns()