Skip to content

Commit 9151b89

Browse files
authored
Merge branch 'TheAlgorithms:master' into master
2 parents 91f6c78 + 74857b7 commit 9151b89

19 files changed

Lines changed: 822 additions & 212 deletions

.github/workflows/Ci.yml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
name: Continuous Integration
22

3-
on: [push, pull_request]
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
48

59
jobs:
610
build:
11+
name: Code style and tests
712
runs-on: ubuntu-latest
813
steps:
914
- uses: actions/checkout@v2
@@ -20,3 +25,14 @@ jobs:
2025

2126
- name: 💄 Code style
2227
run: npm run style
28+
29+
codespell:
30+
name: Check for spelling errors
31+
runs-on: ubuntu-latest
32+
steps:
33+
- uses: actions/checkout@v2
34+
- uses: codespell-project/actions-codespell@master
35+
with:
36+
# file types to ignore
37+
skip: "*.json,*.yml,DIRECTORY.md"
38+
ignore_words_list: "ba,esy,yse"

.github/workflows/Codespell.yml

Lines changed: 0 additions & 13 deletions
This file was deleted.

.github/workflows/UpdateDirectory.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
# This GitHub Action updates the DIRECTORY.md file (if needed) when doing a git push
22
name: Update Directory
33

4-
on: [push]
4+
on:
5+
push:
6+
branches:
7+
- master
58

69
jobs:
710
updateDirectory:

DIRECTORY.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
* [LFUCache](https://github.com/TheAlgorithms/Javascript/blob/master/Cache/LFUCache.js)
1919
* [LRUCache](https://github.com/TheAlgorithms/Javascript/blob/master/Cache/LRUCache.js)
2020
* [Memoize](https://github.com/TheAlgorithms/Javascript/blob/master/Cache/Memoize.js)
21+
* test
22+
* [cacheTest](https://github.com/TheAlgorithms/Javascript/blob/master/Cache/test/cacheTest.js)
2123

2224
## Cellular-Automata
2325
* [ConwaysGameOfLife](https://github.com/TheAlgorithms/Javascript/blob/master/Cellular-Automata/ConwaysGameOfLife.js)
@@ -65,11 +67,13 @@
6567
* Graph
6668
* [Graph](https://github.com/TheAlgorithms/Javascript/blob/master/Data-Structures/Graph/Graph.js)
6769
* [Graph2](https://github.com/TheAlgorithms/Javascript/blob/master/Data-Structures/Graph/Graph2.js)
70+
* [Graph3](https://github.com/TheAlgorithms/Javascript/blob/master/Data-Structures/Graph/Graph3.js)
6871
* Heap
6972
* [MaxHeap](https://github.com/TheAlgorithms/Javascript/blob/master/Data-Structures/Heap/MaxHeap.js)
7073
* [MinHeap](https://github.com/TheAlgorithms/Javascript/blob/master/Data-Structures/Heap/MinHeap.js)
7174
* [MinPriorityQueue](https://github.com/TheAlgorithms/Javascript/blob/master/Data-Structures/Heap/MinPriorityQueue.js)
7275
* Linked-List
76+
* [AddTwoNumbers](https://github.com/TheAlgorithms/Javascript/blob/master/Data-Structures/Linked-List/AddTwoNumbers.js)
7377
* [CycleDetection](https://github.com/TheAlgorithms/Javascript/blob/master/Data-Structures/Linked-List/CycleDetection.js)
7478
* [DoublyLinkedList](https://github.com/TheAlgorithms/Javascript/blob/master/Data-Structures/Linked-List/DoublyLinkedList.js)
7579
* [RotateListRight](https://github.com/TheAlgorithms/Javascript/blob/master/Data-Structures/Linked-List/RotateListRight.js)
@@ -143,6 +147,7 @@
143147
* [Abs](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/Abs.js)
144148
* [AliquotSum](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/AliquotSum.js)
145149
* [Area](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/Area.js)
150+
* [ArithmeticGeometricMean](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/ArithmeticGeometricMean.js)
146151
* [ArmstrongNumber](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/ArmstrongNumber.js)
147152
* [AverageMean](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/AverageMean.js)
148153
* [AverageMedian](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/AverageMedian.js)
@@ -153,6 +158,7 @@
153158
* [CheckKishnamurthyNumber](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/CheckKishnamurthyNumber.js)
154159
* [Coordinate](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/Coordinate.js)
155160
* [CoPrimeCheck](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/CoPrimeCheck.js)
161+
* [DecimalExpansion](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/DecimalExpansion.js)
156162
* [DecimalIsolate](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/DecimalIsolate.js)
157163
* [DegreeToRadian](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/DegreeToRadian.js)
158164
* [EulerMethod](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/EulerMethod.js)
@@ -168,6 +174,7 @@
168174
* [FindHcf](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/FindHcf.js)
169175
* [FindLcm](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/FindLcm.js)
170176
* [FindMin](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/FindMin.js)
177+
* [FindMinIterator](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/FindMinIterator.js)
171178
* [GetEuclidGCD](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/GetEuclidGCD.js)
172179
* [GridGet](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/GridGet.js)
173180
* [IsDivisible](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/IsDivisible.js)
@@ -290,6 +297,7 @@
290297
* [AlternativeStringArrange](https://github.com/TheAlgorithms/Javascript/blob/master/String/AlternativeStringArrange.js)
291298
* [CheckAnagram](https://github.com/TheAlgorithms/Javascript/blob/master/String/CheckAnagram.js)
292299
* [CheckCamelCase](https://github.com/TheAlgorithms/Javascript/blob/master/String/CheckCamelCase.js)
300+
* [CheckExceeding](https://github.com/TheAlgorithms/Javascript/blob/master/String/CheckExceeding.js)
293301
* [CheckFlatCase](https://github.com/TheAlgorithms/Javascript/blob/master/String/CheckFlatCase.js)
294302
* [CheckKebabCase](https://github.com/TheAlgorithms/Javascript/blob/master/String/CheckKebabCase.js)
295303
* [CheckPalindrome](https://github.com/TheAlgorithms/Javascript/blob/master/String/CheckPalindrome.js)

Data-Structures/Linked-List/SingleCircularLinkedList.js.js

Lines changed: 0 additions & 88 deletions
This file was deleted.
Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
// Methods - size, head, isEmpty, getElementAt, addAtFirst, add, clean, insertAt, remove, removeData, printData, get, clear
2+
import { Node } from './SinglyLinkedList.js'
3+
4+
class SinglyCircularLinkedList {
5+
constructor () {
6+
this.headNode = null
7+
this.length = 0
8+
}
9+
10+
// Get size of the linkedList
11+
size = () => this.length
12+
// Get the headNode data
13+
head = () => this.headNode?.data || null
14+
// Check if the linkedList is empty
15+
isEmpty = () => this.length === 0
16+
17+
// initiate the node and index
18+
initiateNodeAndIndex () {
19+
return { currentNode: this.headNode, currentIndex: 0 }
20+
}
21+
22+
// get the data specific to an index
23+
getElementAt (index) {
24+
if (this.length !== 0 && index >= 0 && index <= this.length) {
25+
let { currentNode } = this.initiateNodeAndIndex()
26+
for (let i = 0; i < index && currentNode !== null; i++) {
27+
currentNode = currentNode.next
28+
}
29+
return currentNode
30+
}
31+
return undefined
32+
}
33+
34+
// Add the element in the first position
35+
addAtFirst (data) {
36+
const node = new Node(data)
37+
node.next = this.headNode
38+
this.headNode = node
39+
this.length++
40+
return this.length
41+
}
42+
43+
// Add any data to the end of the linkedList
44+
add (data) {
45+
if (!this.headNode) { return this.addAtFirst(data) }
46+
const node = new Node(data)
47+
// Getting the last node
48+
const currentNode = this.getElementAt(this.length - 1)
49+
currentNode.next = node
50+
node.next = this.headNode
51+
this.length++
52+
return this.length
53+
}
54+
55+
// insert data at a specific position
56+
insertAt (index, data) {
57+
if (index === 0) return this.addAtFirst(data)
58+
if (index === this.length) return this.add(data)
59+
if (index < 0 || index > this.length) throw new RangeError(`Index is out of range max ${this.length}`)
60+
const node = new Node(data)
61+
const previousNode = this.getElementAt(index - 1)
62+
node.next = previousNode.next
63+
previousNode.next = node
64+
this.length++
65+
return this.length
66+
}
67+
68+
// find the first index of the data
69+
indexOf (data) {
70+
let { currentNode } = this.initiateNodeAndIndex()
71+
// initializing currentIndex as -1
72+
let currentIndex = -1
73+
while (currentNode) {
74+
if (currentNode.data === data) {
75+
return currentIndex + 1
76+
}
77+
currentIndex++
78+
currentNode = currentNode.next
79+
}
80+
return -1
81+
}
82+
83+
// remove the data from the end of the list
84+
remove () {
85+
if (this.isEmpty()) return null
86+
const secondLastNode = this.getElementAt(this.length - 2)
87+
const removedNode = secondLastNode.next
88+
secondLastNode.next = this.headNode
89+
this.length--
90+
return removedNode.data || null
91+
}
92+
93+
// remove the data from the first of the list
94+
removeFirst () {
95+
if (this.isEmpty()) return null
96+
const removedNode = this.headNode
97+
if (this.length === 1) {
98+
this.clear()
99+
return removedNode.data
100+
}
101+
const lastNode = this.getElementAt(this.length - 1)
102+
this.headNode = this.headNode.next
103+
lastNode.next = this.headNode
104+
this.length--
105+
return removedNode.data || null
106+
}
107+
108+
// remove the data from the index
109+
removeAt (index) {
110+
if (this.isEmpty()) return null
111+
if (index === 0) return this.removeFirst()
112+
if (index === this.length) return this.remove()
113+
if (index < 0 && index > this.length) return null
114+
const previousNode = this.getElementAt(index - 1)
115+
const currentNode = previousNode.next
116+
previousNode.next = currentNode.next
117+
this.length--
118+
return currentNode.data || null
119+
}
120+
121+
// remove if the data is present
122+
removeData (data) {
123+
if (this.isEmpty()) return null
124+
const index = this.indexOf(data)
125+
return this.removeAt(index)
126+
}
127+
128+
// logs the data
129+
printData (output = value => console.log(value)) {
130+
let { currentIndex, currentNode } = this.initiateNodeAndIndex()
131+
132+
while (currentNode !== null && currentIndex < this.length) {
133+
output(currentNode.data)
134+
currentNode = currentNode.next
135+
currentIndex++
136+
}
137+
}
138+
139+
// get the data from the linkedList
140+
get () {
141+
let { currentIndex, currentNode } = this.initiateNodeAndIndex()
142+
const list = []
143+
while (currentNode !== null && currentIndex < this.length) {
144+
list.push(currentNode.data)
145+
currentNode = currentNode.next
146+
currentIndex++
147+
}
148+
return list
149+
}
150+
151+
clear () {
152+
this.headNode = null
153+
this.length = 0
154+
}
155+
}
156+
157+
export { SinglyCircularLinkedList }

0 commit comments

Comments
 (0)