Skip to content

Commit

Permalink
Issue TheAlgorithms#191: Fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
skdotv committed Oct 15, 2022
1 parent fbdb7bd commit 00c4895
Show file tree
Hide file tree
Showing 11 changed files with 20 additions and 16 deletions.
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);
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;

// 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/breadth_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 @@ -42,7 +42,7 @@ class Graph {

List<int> breadthFirstSearch(Graph graph, int numberOfNodes, int startNode) {
Queue queue = new Queue<int>();
List<int> answer = List();
List<int> answer = [];
queue.add(startNode);
while (queue.isNotEmpty) {
int node = queue.removeFirst();
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
3 changes: 2 additions & 1 deletion other/N_bonacci.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
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
5 changes: 3 additions & 2 deletions sort/merge_sort.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ 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;

List 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
3 changes: 2 additions & 1 deletion sort/pigeonhole_sort.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ void pigeonholeSort(List arr) {
int range = max - min;
range++;

List phole = new List(range);
List phole = []..length = range;

for (int i = 0; i < range; i++) {
phole[i] = 0;
}
Expand Down
2 changes: 1 addition & 1 deletion sort/quick_Sort.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'dart:math' show Random;
// quickSort
// O(n*log n)
void main() {
var list = List<int>();
var list = [];
Random random = new Random();
for (var i = 0; i < 100; i++) {
list.add(random.nextInt(100));
Expand Down
2 changes: 1 addition & 1 deletion sort/tim_Sort.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ void insertionSort(List list, int left, int right) {

void merge(List list, int left, int middle, int right) {
int length1 = middle - left + 1, length2 = right - middle;
List leftList = new List(length1), rightList = new List(length2);
List leftList = []..length = length1, rightList = []..length = length2;

for (int i = 0; i < length1; i++) {
leftList[i] = list[left + i];
Expand Down

0 comments on commit 00c4895

Please sign in to comment.