def test_partition_max_elt_pivot(self):
     array = [9, 12, 3, 1, 6, 8, 2, 5, 14, 13, 11, 7, 10, 4, 0]
     pivot = 14
     pivot_idx = array.index(pivot)
     init_len = len(array)
     Quicksort.partition_array(array, pivot_idx, 0, init_len)
     self.check_partition_valid(array, init_len, pivot, 0, init_len)
 def test_partition_partial_subset_right(self):
     array = [9, 12, 3, 1, 6, 8, 2, 5, 14, 13, 11, 7, 10, 4, 0]
     pivot = 6
     pivot_idx = array.index(pivot)
     init_len = len(array)
     Quicksort.partition_array(array, pivot_idx, 2, init_len)
     self.check_partition_valid(array, init_len, pivot, 2, init_len)
 def test_partition_with_dups(self):
     array = [9, 12, 3, 2, 1, 6, 8, 2, 6]
     pivot = 6
     pivot_idx = array.index(pivot)
     init_len = len(array)
     Quicksort.partition_array(array, pivot_idx, 0, init_len)
     self.check_partition_valid(array, init_len, pivot, 0, init_len)
 def test_partition_full(self):
     array = [9, 12, 3, 1, 6, 8, 2, 5, 14, 13, 11, 7, 10, 4, 0]
     pivot = 8
     pivot_idx = array.index(pivot)
     init_len = len(array)
     Quicksort.partition_array(array, pivot_idx, 0, init_len)
     self.check_partition_valid(array, init_len, pivot, 0, init_len)
     self.assertEqual(pivot, array[pivot])
 def test_quicksort_mixed_order_list(self):
     array = [9, 12, 3, 1, 6, 8, 2, 5, 14, 13, 11, 7, 10, 4, 0]
     sorted_list = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]
     result = Quicksort.quicksort(array)
     self.assertEqual(sorted_list, result)
e=[5,5,1,5,5,1,5,5]
f=[1,4,7,2,6,9,0,76,3,6,1,6,2,5,3,1,1,2,6,2,8,6,3,1,8,54,1,2,3,9,8,7,1,3,2,4]
g=rand.sample( range(0,100) , 25 )
h=rand.sample( range(0,10000) , 1000 )
mylist=[a,b,c,d,e,f,g,h]


print "-------bubblesort------"
for eachlist in mylist:
    print eachlist if len(eachlist)<40 else "%s ..." %eachlist[:25]
    sorted_list = Bubblesort.bubblesort(eachlist)
    print sorted_list if len(eachlist)<40 else "%s ..." %sorted_list[:25]

print "-------mergesort------"
for eachlist in mylist:
    print eachlist if len(eachlist)<40 else "%s ..." %eachlist[:25]
    sorted_list =  Mergesort.mergesort(eachlist)
    print sorted_list if len(eachlist)<40 else "%s ..." %sorted_list[:25]

print "-------quicksort------"
for eachlist in mylist:
    print eachlist if len(eachlist)<40 else "%s ..." %eachlist[:25]
    sorted_list =  Quicksort.quicksort(eachlist)
    print sorted_list if len(eachlist)<40 else "%s ..." %sorted_list[:25]

print "-------shellsort------"
for eachlist in mylist:
    print eachlist if len(eachlist)<40 else "%s ..." %eachlist[:25]
    sorted_list =  Shellsort.shellsort(eachlist)
    print sorted_list if len(eachlist)<40 else "%s ..." %sorted_list[:25]
# main.py -- put your code here!
import pyb
import Quicksort
file = open("trash.txt","w")
a = []
for i in range(0,250):
	a.append(pyb.rng()%250)
b = Quicksort.quicksort(a)

file.write(str(b))
file.close()
import Book
import Quicksort

got = Book.Book('A Game of Thrones', Book.Author('George R. R.', 'Martin'),
                '978-0553573404', 694)
hp = Book.Book('Harry Potter and the Philosophers Stone',
               Book.Author('Joanne K.', 'Rowling'), '978-1408855652', 331)
lotr = Book.Book('Lord of the Rings: The Fellowship of the Rings',
                 Book.Author('John Ronald Reuel', 'Tolkien'), '978-0261102354',
                 529)

library = [got, hp, lotr]

Quicksort.quicksort(library)

for n in library:
    print(str(n) + "\n")
Beispiel #9
0
            print("----------------------------------------------------")
            print()

    for i in range(len(Liste_der_listen_mit_anzahl_der_woerter)):

        if Laufzeitcheck:
            laenge = Liste_der_listen_mit_anzahl_der_woerter[i]

        Liste = Listen_Dateien.get_list(random_check, laenge, Laufzeitcheck)  # Die datei wird in ne Liste umgewandelt

        if not Laufzeitcheck:
            datei_schreiben = Listen_Dateien.neue_datei()

        start_time = time.time()
        print("startet sortieren")
        erg = Quicksort.quicksort(Liste, 0, len(Liste) - 1)  # sortierte Liste wird in erg gespeichert

        finish_time = time.time() - start_time

        if Laufzeitcheck:
            Liste_Zeiten.append(finish_time)
            Liste_laengen.append(Liste_der_listen_mit_anzahl_der_woerter[i])

    if not Laufzeitcheck:

        f = open(datei_schreiben, "w", encoding="utf-8")  # neue Datei mit eingegebenem Pfad erstellt
        print()
        print("----------------------------------------------------")
        print()
        print(
            "Sollte ihre Liste nicht zu ihrer zufriedenheit sortiert wurden sein, Führen sie die Datei erneut aus und achten darauf, das die Wörter einheitlisch getrennt sind, und sie die Trennung korrekt angegeben haben")
Beispiel #10
0

for j in range(iterazioni):
    print("iterazione ", j+1)
    i_current_tomes = []
    q_current_times = []

    for i in N:
        vi = gnrt.random_list(i)
        vq = vi[:]
        init = timer()
        isrt.insertionsort(vi)
        i_current_tomes.append(timer() - init)

        init = timer()
        qsrt.quicksort(vq, 0, (len(vq) - 1))
        q_current_times.append(timer() - init)

    itimes.append(i_current_tomes)
    qtimes.append(q_current_times)

i_average = []
q_average = []

length_vectors = int(max_elements / passo)

for i in range(length_vectors):
    pi = 0
    pq = 0
    for j in range(iterazioni):
        pi += itimes[j][i]