Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 class SortHelper { | 5 class SortHelper { |
| 6 | 6 |
| 7 SortHelper(this.sortFunction, this.compareFunction) {} | 7 SortHelper(this.sortFunction, this.compareFunction) {} |
| 8 | 8 |
| 9 void run() { | 9 void run() { |
| 10 testSortIntLists(); | 10 testSortIntLists(); |
| 11 testSortDoubleLists(); | 11 testSortDoubleLists(); |
| 12 } | 12 } |
| 13 | 13 |
| 14 void printList(List a) { | 14 void printList(List a) { |
| 15 StringBuffer buffer = new StringBuffer(); | 15 StringBuffer buffer = new StringBuffer(); |
| 16 for (int i = 0; i < a.length; i++) { | 16 for (int i = 0; i < a.length; i++) { |
| 17 if (i != 0) buffer.add(","); | 17 if (i != 0) buffer.add(","); |
| 18 buffer.add(a[i]); | 18 buffer.add(a[i]); |
| 19 } | 19 } |
| 20 print("[$buffer]"); | 20 print("[$buffer]"); |
| 21 } | 21 } |
| 22 | 22 |
| 23 void isSorted(List a) { | 23 bool isSorted(List a) { |
|
jimhug
2011/11/11 15:02:02
Do you know why frog is the first one catching the
| |
| 24 for (int i = 1; i < a.length; i++) { | 24 for (int i = 1; i < a.length; i++) { |
| 25 if (compareFunction(a[i - 1], a[i]) > 0) { | 25 if (compareFunction(a[i - 1], a[i]) > 0) { |
| 26 return false; | 26 return false; |
| 27 } | 27 } |
| 28 } | 28 } |
| 29 return true; | 29 return true; |
| 30 } | 30 } |
| 31 | 31 |
| 32 void testSortIntLists() { | 32 void testSortIntLists() { |
| 33 List a = new List(40); | 33 List a = new List(40); |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 153 | 153 |
| 154 for (int i = 0; i < a.length; i++) { | 154 for (int i = 0; i < a.length; i++) { |
| 155 a[i] = 1.5; | 155 a[i] = 1.5; |
| 156 } | 156 } |
| 157 testSort(a); | 157 testSort(a); |
| 158 } | 158 } |
| 159 | 159 |
| 160 Function sortFunction; | 160 Function sortFunction; |
| 161 Function compareFunction; | 161 Function compareFunction; |
| 162 } | 162 } |
| OLD | NEW |