Sortero

Hecho en 🇵🇷 por Radamés J. Valentín Reyes

Import

import 'package:sortero/sortero.dart';

Extensions:

- Bubble sort:

extension

.bubbleSort()

Parameters

  • compare: a function that takes as argument one item of a list and returns a number
  • reverseOrder: boolean value that determines the order in which stuff is sorted

Example

Bubble sort

List<num> algo = [4,6,3,7,8,9];
    algo.bubbleSort(
	compare: (a){
		return a;
	},
);
print(algo);

Bubble sort reverseOrder parameter

List<num> algo = [4,6,3,7,8,9];
    algo.bubbleSort(
      compare: (a){
        return a;
      },
      reverseOrder: true,
    );
	print(algo);
});

Bubble sort async

List<num> algo = [4,6,3,7,8,9];
await algo.bubbleSortAsync(
  compare: (a)async{
    return a;
  },
  reverseOrder: true,
);
print(algo);

Pseudo alphabetic sorting

Use the new getWordValue function to get a numeric value that can be used to kind of sort items alphabetically.

List<String> words = ["Perro", "Gato", "Camión", "Alfombra"];
print(words);
words.bubbleSort(
  compare: (word){
    return getWordValue(word);
  },
);
print("Sorted words: $words");

Libraries

sortero