summaryrefslogtreecommitdiff
path: root/week2/Bubblesort.cs
blob: 82ceb4fe987343e81a06b998fe87d45c8d69fd5f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
namespace ALGA {
	public class Bubblesort {
		public static void bubblesort(ISortList list) {
			for (int i = 0; i < list.Count - 1; i++) {
				bool swapped = false;

				for (int j = 0; j < list.Count - i - 1; j++) {
					if (list.compare(j, j + 1) <= 0) continue;

					list.swap(j, j + 1);
					swapped = true;
				}

				if (!swapped) break;
			}
		}
	}
}