0 purchases
sort
sort #
package for sorting numbers, lists, maps, doubles and dates with quick and simple sort algorithms
Getting Started #
This package has two sorting algorithms at the moment, one in simple sort that comes from dart it self and other one is quick sort algorithm.
Implementation #
Add package in your pubspec.yaml file
dependencies:
sort: ^0.0.1
copied to clipboard
Import the package as
import 'package:sort/sort.dart';
copied to clipboard
For list of int, double numbers and dateTime
Simple sort
var numbers = [9.0,3.1,2.3,6.1,4.5,5.3,1.6,8.3,7.9];
numbers.simpleSort();
print('$numbers');
//numbers is now as [1.6,2.3,3.1,4.5,5.3,6.1,7.9,8.3,9.0]
copied to clipboard
Quick sort
var numbers = [9.0,3.1,2.3,6.1,4.5,5.3,1.6,8.3,7.9];
numbers.quickSort();
print('$numbers');
//numbers is now as [1.6,2.3,3.1,4.5,5.3,6.1,7.9,8.3,9.0]
copied to clipboard
Add a value and sort list
var numbers = [9,3,2,6,4,5,1,7];
numbers.addAndSort(item:8);
print('$numbers');
//numbers is now as [1,2,3,4,5,6,7,8,9]
copied to clipboard
For list of String
List of String has only simple sort
var names = ['bac','cab','abc'];
names.simpleSort();
print('$names');
//names is now as ['abc','bac,','cab']
copied to clipboard
Add a string to the list and sort
var names = ['bac','dab','abc'];
names.addAndSort(item:'abc');
print('$names');
//names is now as ['abc','bac,','cab','dab']
copied to clipboard
For list of Maps
Simple sort
var maps = [
{'age':12,'name':'abc'},
{'age':11,'name':'bac'},
{'age':16,'name':'cab'},
];
maps.simpleSort(sortBy: 'age');
print('$maps');
//sortedMaps is now as [{'age':11,'name':'bac'},{'age':12,'name':'abc'},{'age':16,'name':'cab'}]
copied to clipboard
Quick sort
var maps = [
{'age':12,'name':'abc'},
{'age':11,'name':'bac'},
{'age':16,'name':'cab'},
];
maps.quickSort(sortBy: 'age');
print('$maps');
//sortedMaps is now as [{'age':11,'name':'bac'},{'age':12,'name':'abc'},{'age':16,'name':'cab'}]
copied to clipboard
Add a value and sort list
var maps = [
{'age':12,'name':'abc'},
{'age':11,'name':'bac'},
{'age':16,'name':'cab'},
];
maps.addAndSort(item:{'age':14,'name':'dac'},sortBy: 'age');
print('$maps');
//sortedMaps is now as [{'age':11,'name':'bac'},{'age':12,'name':'abc'},{'age':14,'name':'dac'},{'age':16,'name':'cab'}]
copied to clipboard
Soon more sorts for short lists, long lists and very long lists will be added to sort lists in very least time.
Support Us #
You like the package ? Buy me a coffee :)
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.