Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes: 200 #201

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion data_structures/HashMap/Hashing.dart
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ class HashMap {
List<LinkedList> buckets;

HashMap(int hsize) {
buckets = new List<LinkedList>(hsize);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think assigning length value is not a good practice. Can we change the constructor to List.filled()

buckets = []..length = hsize;

for (int i = 0; i < hsize; i++) {
buckets[i] = new LinkedList();
}
Expand Down
2 changes: 1 addition & 1 deletion data_structures/Queue/Circular_Queue.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const int MAX_SIZE = 10;

class CircularQueue<T> {
int start = -1, end = -1;
List<T> queue = new List<T>(MAX_SIZE);
List<T> queue = []..length = MAX_SIZE;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think assigning length value is not a good practice. Can we change the constructor to List.filled()


// insert elements into the queue
void enque(T element) {
Expand Down
2 changes: 1 addition & 1 deletion data_structures/Queue/List_Queue.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const int MAX_SIZE = 10;

class ListQueue<T> {
int count = 0;
List<T> queue = new List<T>(MAX_SIZE);
List<T> queue = []..length = MAX_SIZE;

//Checks if the queue has elements (not empty)
bool hasElements() {
Expand Down
2 changes: 1 addition & 1 deletion data_structures/linked_list/cycle_in_linked_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ Node findCyclicNode(Node headNode) {

void main() {
LinkedList linkedList = LinkedList();
List<Node> allNodes = List();
List<Node> allNodes = [];
for (var i = 0; i <= 10; i++) {
Node newNode = createNode(i);
linkedList.insert(newNode);
Expand Down
6 changes: 3 additions & 3 deletions graphs/depth_first_search.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Graph {
/// each node will have a list as value which stores
/// the nodes to which it is connected to
for (int i = 0; i < this.nodes.length; i++) {
this.graph[nodes[i]] = List();
this.graph[nodes[i]] = [];
}
}

Expand All @@ -32,7 +32,7 @@ class Graph {

void addNodes(int newNode) {
this.nodes.add(newNode);
this.graph[newNode] = List();
this.graph[newNode] = [];
}

void addEdges(int start, int end) {
Expand All @@ -59,7 +59,7 @@ List<int> depthFirstSearch(Graph graph, int numberOfNodes, int startNode) {
List<bool> visitedNodes =
new List<bool>.generate(numberOfNodes, (index) => false);

List<int> answer = List();
List<int> answer = [];
depthFirstSearchHelper(graph.graph, visitedNodes, startNode, answer);
return answer;
}
Expand Down
2 changes: 1 addition & 1 deletion other/N_bonacci.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:test/test.dart';

List N_bonacci(int n, int m) {
List v = new List(m);
List v = []..length = m;
var i;
for (i = 0; i < m; i++) {
v[i] = 0;
Expand Down
3 changes: 1 addition & 2 deletions sort/merge_sort.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ void merge(List list, int lIndex, int mIndex, int rIndex) {
int lSize = mIndex - lIndex + 1;
int rSize = rIndex - mIndex;

List lList = new List(lSize);
List rList = new List(rSize);
List lList = []..length = lSize, rList = []..length = rSize;

for (int i = 0; i < lSize; i++) lList[i] = list[lIndex + i];
for (int j = 0; j < rSize; j++) rList[j] = list[mIndex + j + 1];
Expand Down