Guest User

Untitled

a guest
Jun 17th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
D 0.94 KB | None | 0 0
  1. void bubble(alias less = "a < b", Range)(Range datas) {
  2.     import std.functional;
  3.     alias binaryFun!(less) lessFun;
  4.    
  5.     size_t lastSwap = datas.length;
  6.     foreach(size_t i, ref a; datas) {
  7.         import std.range;
  8.         import std.array;
  9.         pragma(msg, typeof(datas));
  10.         datas.popFront;
  11.        
  12.         auto previous = chunks(datas.save, lastSwap - i);
  13.         if(current.empty) break;
  14.        
  15.         auto current = previous.save;
  16.         current.popFront();
  17.         if(current.empty) break;
  18.        
  19.         // Args are reversed so i have the value we want to assign to lastSwap;
  20.         foreach(size_t i, ref b, ref a; lockstep(current, previous)) {
  21.             if(lessFun(b, a)) {
  22.                 import std.algorithm;
  23.                 swap(b, a);
  24.                
  25.                 lastSwap = i;
  26.             }
  27.         }
  28.     }
  29. }
  30.  
  31. void main() {
  32.     bubble([1, 2, 3, 0]);
  33. }
  34.  
  35. ->
  36.  
  37. int[]
  38. sort/bubble.d(12): Error: undefined identifier module bubble.popFront
  39. sort/bubble.d(14): Error: undefined identifier module bubble.save
  40. sort/bubble.d(15): Error: undefined identifier current
Add Comment
Please, Sign In to add comment