This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Node { | |
Node(this.value, {this.next}); | |
int value; | |
Node? next; | |
@override | |
String toString() { | |
final result = StringBuffer(); | |
result.write(value); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void main() { | |
// final myList = [1, 2, 4, 5, 5, 6, 7, 8, 9, 10]; | |
final myList = [1, 1, 1, 2, 2, 2, 3, 3, 4, 5]; | |
final searchItem = 4; | |
final index = binarySearch(myList, searchItem); | |
if (index == null) { | |
print('not found'); | |
} else { | |
print("found searchitem at index $index"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void main() { | |
print("Original:"); | |
final myList = [6, 9, 4, 1, 8, 5, 4, 3]; | |
print(myList); | |
insertionSort(myList); | |
print("Sorted:"); | |
print(myList); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void main() { | |
final mylist = [6, 5, 4, 3, 2, 1]; | |
bubbleSort(mylist); | |
//expecting [1, 2, 3, 4, 5, 6] | |
print(mylist); | |
} | |
void bubbleSort(List<int> mylist) { | |
for (int j = 0; j < mylist.length -1; j++) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:typed_data'; | |
void main() { | |
final myList = MyList(); | |
// Test with small numbers (1 byte) | |
print("Testing small numbers (1 byte each):"); | |
myList.add(10); | |
myList.add(255); | |
print("List: $myList"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:typed_data'; | |
void main() { | |
final myList = MyList(); | |
print(myList.length); | |
myList.add(10); | |
myList.add(1); | |
print(myList.length); | |
print(myList); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:typed_data'; | |
void main() { | |
final myList = MyList(); | |
print(myList.length); | |
myList.add(10); | |
print(myList.length); | |
print(myList); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
1. Constant time complexity. | |
2. Linear time complexity. | |
3. Quadratic time complexity. | |
4. Logarithmic time complexity. | |
*/ | |
import 'dart:math'; | |
void main() { |