1 public int[] Ripple(int[] sortData) 2 { 3 int StartIndex = 1; 4 int top = sortData.Length - 1; 5 int Bottom = 0; 6 int step = 1; 7 int swap; 8 while (Bottom < top) 9 { 10 for (int i = StartIndex; Bottom <= i && i <= top; i = i + step) 11 { 12 if (step == 1) 13 { 14 if (sortData[i] < sortData[i - 1]) 15 { 16 swap = sortData[i]; 17 sortData[i] = sortData[i - 1]; 18 sortData[i - 1] = swap; 19 } 20 } 21 else 22 { 23 if (sortData[i + 1] < sortData[i]) 24 { 25 swap = sortData[i]; 26 sortData[i] = sortData[i + 1]; 27 sortData[i + 1] = swap; 28 } 29 } 30 } 31 if (step == -1) 32 { 33 Bottom++; 34 StartIndex = Bottom + 1; 35 } 36 else 37 { 38 top--; 39 StartIndex = top - 1; 40 } 41 step = step * -1; 42 } 43 44 return sortData; 45 }