Added Dart examples for chapter 3 to chapter 9 (#265)
* fix: corrected method return value following Dart's newest linter version * feat: added Dart recursion examples for chapter 3 * feat: added quicksort example in Dart for chapter 4 * feat: added examples in Dart for the chapter 5 * feat: added Dart example for chapter 6 bfs * feat: added djikstra example in Dart for chapter 7 * feat: added example of set covering in Dart for chapter 8 * feat: added examples for dynamic programming in dart for chapter 9
This commit is contained in:
15
05_hash_tables/dart/01_price_of_groceries.dart
Normal file
15
05_hash_tables/dart/01_price_of_groceries.dart
Normal file
@@ -0,0 +1,15 @@
|
||||
void main(List<String> args) {
|
||||
final book = <String, double>{};
|
||||
book.addAll(
|
||||
{
|
||||
'apple': 0.67,
|
||||
'milk': 1.49,
|
||||
'avocado': 1.49,
|
||||
},
|
||||
);
|
||||
|
||||
print(book);
|
||||
print(book['apple']);
|
||||
print(book['milk']);
|
||||
print(book['avocado']);
|
||||
}
|
||||
16
05_hash_tables/dart/02_check_voter.dart
Normal file
16
05_hash_tables/dart/02_check_voter.dart
Normal file
@@ -0,0 +1,16 @@
|
||||
void main(List<String> args) {
|
||||
final voted = <String, bool>{};
|
||||
|
||||
checkVoter('tom', voted);
|
||||
checkVoter('mike', voted);
|
||||
checkVoter('mike', voted);
|
||||
}
|
||||
|
||||
void checkVoter(String name, Map<String, bool> voted) {
|
||||
if (voted[name] != null) {
|
||||
print('Kick them out!');
|
||||
} else {
|
||||
voted[name] = true;
|
||||
print('Let them vote');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user