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
//List to implement stack behavior (LIFO) | |
class Queue<T> { | |
final List<T> _items = []; | |
/// Adds an item to the back of the queue. | |
void enqueue(T item) => _items.add(item); | |
/// Removes and returns the item from the front of the queue. | |
/// Returns `null` if the queue is empty. |
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
//dart does not have bult in stack data type, so we will implement it with List | |
class Stack<T> { | |
final List<T> _items = []; | |
/// Pushes an item onto the top of the stack. | |
void push(T item) => _items.add(item); | |
/// Removes and returns the item at the top of the stack. | |
/// Returns `null` if the stack is empty. |
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
//declare AppLifeCyleListener | |
late final AppLifecycleListener _lifecycleListener; | |
//initialize AppLifeCycleListener | |
@override | |
void onInit() { | |
super.onInit(); | |
_lifecycleListener = AppLifecycleListener( | |
onResume: () => debugPrint('app resumed'), |
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
# Specify analysis options. | |
# | |
# For a list of lints, see: https://dart.dev/tools/linter-rules | |
# For guidelines on configuring static analysis, see: | |
# https://dart.dev/tools/analysis | |
# | |
# There are other similar analysis options files in the flutter repos, | |
# which should be kept in sync with this file: | |
# | |
# - analysis_options.yaml (this file) |
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:math'; | |
class ArmstrongNumbers { | |
bool isArmstrongNumber(int number) { | |
int userGivenNumber = number; | |
int temp = 0; | |
int totalDigits = 0; | |
int individualDigit = 0; | |
int sum = 0; |
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
String reverse(String inputString) { | |
String reversedString; | |
//using split() method to splt the string into characters | |
List<String> chars = inputString.split(""); | |
//using .reversed.join() to joing the charaters to form a reversed string | |
reversedString = chars.reversed.join(); | |
return reversedString; | |
} |
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 PrimeFactors { | |
List<int> result = []; | |
List<int> factors(int num) { | |
for (var i = 2; i < num; i++) { | |
if (num % i == 0) { | |
break; | |
} else { | |
result.add(i); | |
} | |
} |
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 Leap { | |
bool leapYear(int year) { | |
if (year % 4 == 0 && year % 400 == 0) { | |
return true; | |
} else { | |
return false; | |
} | |
} | |
} |
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
String helloWorld() { | |
return "Hello, World!"; | |
} |
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
String twoFer([String? name = null]) { | |
if (name == null) { | |
return 'One for you, one for me.'; | |
} else { | |
return 'One for ' + name + ', one for me.'; | |
} | |
} |