Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void bubble(alias less = "a < b", Range)(Range datas) {
- import std.functional;
- alias binaryFun!(less) lessFun;
- size_t lastSwap = datas.length;
- foreach(size_t i, ref a; datas) {
- import std.range;
- import std.array;
- pragma(msg, typeof(datas));
- datas.popFront;
- auto previous = chunks(datas.save, lastSwap - i);
- if(current.empty) break;
- auto current = previous.save;
- current.popFront();
- if(current.empty) break;
- // Args are reversed so i have the value we want to assign to lastSwap;
- foreach(size_t i, ref b, ref a; lockstep(current, previous)) {
- if(lessFun(b, a)) {
- import std.algorithm;
- swap(b, a);
- lastSwap = i;
- }
- }
- }
- }
- void main() {
- bubble([1, 2, 3, 0]);
- }
- ->
- int[]
- sort/bubble.d(12): Error: undefined identifier module bubble.popFront
- sort/bubble.d(14): Error: undefined identifier module bubble.save
- sort/bubble.d(15): Error: undefined identifier current
Add Comment
Please, Sign In to add comment