Untitled
unknown
plain_text
2 months ago
1.1 kB
6
Indexable
class SelectionSort(): def __init__(self): self.tab = [] def fill (self): print("wypelnij 10 liczb calkowitych") for _ in range(10): n = int(input("podaj liczbe: ")) self.tab.append(n) def show (self): print(self.tab) def _findMax(self, startIndex): maxIndex = startIndex for i in range(startIndex+1, len(self.tab)): if self.tab[i] > self.tab(maxIndex): maxIndex = 1 return maxIndex def _findMin(self, startIndex): minIndex = startIndex for i in range(startIndex+1, len(self.tab)): if self.tab[i] < self.tab(minIndex): minIndex = 1 return minIndex def sort (self, asc): for i in range(len(self.tab)-1): index = self._findMax(i) if asc else self._findMin(i) self.tab[i], self.tab[index] = self.tab[index], self.tab[i] sortedTab = SelectionSort() sortedTab.fill() sortedTab.show() sortedTab.sort(asc=True) sortedTab.show()
Editor is loading...
Leave a Comment