Comparing version 0.0.2-test to 0.0.3-test
@@ -11,2 +11,3 @@ "use strict"; | ||
this.next = null; | ||
this.prev = null; | ||
} | ||
@@ -17,6 +18,62 @@ } | ||
this.logger = new Logger_1.default(); | ||
this.size = 0; | ||
this.head = null; | ||
this.logger.log("DoublyLinkedList created" + this.head); | ||
this.tail = null; | ||
} | ||
isEmpty() { | ||
return this.size === 0; | ||
} | ||
addFirst(value) { | ||
const newNode = new ListNode(value); | ||
if (this.isEmpty()) { | ||
this.tail = newNode; | ||
} | ||
else { | ||
newNode.next = this.head; | ||
if (this.head) { | ||
this.head.prev = newNode; | ||
} | ||
} | ||
this.head = newNode; | ||
this.size++; | ||
} | ||
addLast(value) { | ||
const newNode = new ListNode(value); | ||
if (this.isEmpty()) { | ||
this.head = newNode; | ||
} | ||
else { | ||
if (this.tail) { | ||
this.tail.next = newNode; | ||
} | ||
newNode.prev = this.tail; | ||
} | ||
this.tail = newNode; | ||
this.size++; | ||
} | ||
print() { | ||
if (this.isEmpty()) { | ||
return this.logger.info("List is empty"); | ||
} | ||
const listValues = []; | ||
let current = this.head; | ||
while (current) { | ||
listValues.push(current.value); | ||
current = current.next; | ||
} | ||
this.logger.info(listValues); | ||
} | ||
printReverse() { | ||
if (this.isEmpty()) { | ||
return this.logger.info("List is empty"); | ||
} | ||
const listValues = []; | ||
let current = this.tail; | ||
while (current) { | ||
listValues.push(current.value); | ||
current = current.prev; | ||
} | ||
this.logger.info(listValues); | ||
} | ||
} | ||
exports.default = DoublyLinkedList; |
@@ -27,2 +27,40 @@ "use strict"; | ||
} | ||
poll() { | ||
return this.removeFirst(); | ||
} | ||
add(indexOrValue, value) { | ||
if (typeof indexOrValue === "number" && value !== undefined) { | ||
this.addAtIndex(indexOrValue, value); | ||
} | ||
else { | ||
this.addLast(indexOrValue); | ||
} | ||
} | ||
addAtIndex(index, value) { | ||
if (index < 0 || index > this.size) { | ||
throw new Error("Index out of bounds"); | ||
} | ||
if (index === 0) { | ||
this.addFirst(value); | ||
return; | ||
} | ||
if (index === this.size) { | ||
this.addLast(value); | ||
return; | ||
} | ||
let current = this.head; | ||
let previous = null; | ||
let i = 0; | ||
while (i < index) { | ||
previous = current; | ||
current = (current === null || current === void 0 ? void 0 : current.next) || null; | ||
i++; | ||
} | ||
const newNode = new ListNode(value); | ||
newNode.next = current; | ||
if (previous) { | ||
previous.next = newNode; | ||
} | ||
this.size++; | ||
} | ||
addFirst(value) { | ||
@@ -121,3 +159,76 @@ const newNode = new ListNode(value); | ||
} | ||
indexOf(value) { | ||
let current = this.head; | ||
let index = 0; | ||
while (current) { | ||
if (current.value === value) { | ||
return index; | ||
} | ||
current = current.next; | ||
index++; | ||
} | ||
return -1; | ||
} | ||
getFirst() { | ||
var _a, _b; | ||
return (_b = (_a = this.head) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : null; | ||
} | ||
getLast() { | ||
var _a, _b; | ||
return (_b = (_a = this.tail) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : null; | ||
} | ||
removeAt(index) { | ||
var _a; | ||
if (index < 0 || index >= this.size) { | ||
return null; | ||
} | ||
if (index === 0) { | ||
return this.removeFirst(); | ||
} | ||
if (index === this.size - 1) { | ||
return this.removeLast(); | ||
} | ||
let current = this.head; | ||
let previous = null; | ||
let i = 0; | ||
while (i < index) { | ||
previous = current; | ||
current = (current === null || current === void 0 ? void 0 : current.next) || null; | ||
i++; | ||
} | ||
if (previous) { | ||
previous.next = (current === null || current === void 0 ? void 0 : current.next) || null; | ||
} | ||
this.size--; | ||
return (_a = current === null || current === void 0 ? void 0 : current.value) !== null && _a !== void 0 ? _a : null; | ||
} | ||
remove(value) { | ||
let current = this.head; | ||
let previous = null; | ||
while (current) { | ||
if (current.value === value) { | ||
if (previous) { | ||
previous.next = current.next; | ||
} | ||
else { | ||
this.head = current.next; | ||
} | ||
this.size--; | ||
return true; | ||
} | ||
previous = current; | ||
current = current.next; | ||
} | ||
return false; | ||
} | ||
toArray() { | ||
let current = this.head; | ||
const listValues = []; | ||
while (current) { | ||
listValues.push(current.value); | ||
current = current.next; | ||
} | ||
return listValues; | ||
} | ||
} | ||
exports.default = SingleLinkedList; |
@@ -6,5 +6,19 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.binarySearch = exports.Logger = exports.LinkedList = exports.Queue = exports.Stack = exports.SingleLinkedList = void 0; | ||
const binarySearch_1 = __importDefault(require("./Algorithms/binarySearch")); | ||
exports.quickSort = exports.mergeSort = exports.insertionSort = exports.bubbleSort = exports.recursiveBinarySearch = exports.linearSearch = exports.factorial = exports.binarySearch = exports.Logger = exports.LinkedList = exports.Queue = exports.Stack = exports.SingleLinkedList = void 0; | ||
const binarySearch_1 = __importDefault(require("./Algorithms/search/binarySearch")); | ||
exports.binarySearch = binarySearch_1.default; | ||
const factorial_1 = __importDefault(require("./Algorithms/search/factorial")); | ||
exports.factorial = factorial_1.default; | ||
const linearSearch_1 = __importDefault(require("./Algorithms/search/linearSearch")); | ||
exports.linearSearch = linearSearch_1.default; | ||
const recursiveBinarySearch_1 = __importDefault(require("./Algorithms/search/recursiveBinarySearch")); | ||
exports.recursiveBinarySearch = recursiveBinarySearch_1.default; | ||
const bubbleSort_1 = __importDefault(require("./Algorithms/sort/bubbleSort")); | ||
exports.bubbleSort = bubbleSort_1.default; | ||
const insertionSort_1 = __importDefault(require("./Algorithms/sort/insertionSort")); | ||
exports.insertionSort = insertionSort_1.default; | ||
const mergeSort_1 = __importDefault(require("./Algorithms/sort/mergeSort")); | ||
exports.mergeSort = mergeSort_1.default; | ||
const quickSort_1 = __importDefault(require("./Algorithms/sort/quickSort")); | ||
exports.quickSort = quickSort_1.default; | ||
const DoublyLinkedList_1 = __importDefault(require("./dataStructures/DoublyLinkedList")); | ||
@@ -11,0 +25,0 @@ exports.LinkedList = DoublyLinkedList_1.default; |
{ | ||
"name": "dsacjs", | ||
"version": "0.0.2-test", | ||
"version": "0.0.3-test", | ||
"description": "A high-performance JavaScript and TypeScript library offering a comprehensive set of efficient data structures. Simplify your algorithm implementation and data manipulation with optimized, easy-to-use tools.", | ||
@@ -5,0 +5,0 @@ "main": "./dist/index.js", |
@@ -0,5 +1,19 @@ | ||
declare class ListNode<T = any> { | ||
value: T; | ||
next: ListNode<T> | null; | ||
prev: ListNode<T> | null; | ||
constructor(value: T); | ||
} | ||
export default class DoublyLinkedList<T = any> { | ||
private readonly logger; | ||
private readonly head; | ||
head: ListNode<T> | null; | ||
tail: ListNode<T> | null; | ||
size: number; | ||
constructor(); | ||
isEmpty(): boolean; | ||
addFirst(value: T): void; | ||
addLast(value: T): void; | ||
print(): void; | ||
printReverse(): void; | ||
} | ||
export {}; |
@@ -14,2 +14,6 @@ declare class ListNode<T = any> { | ||
peek(): T | null; | ||
poll(): T | null; | ||
add(value: T): void; | ||
add(index: number, value: T): void; | ||
private addAtIndex; | ||
addFirst(value: T): void; | ||
@@ -22,3 +26,9 @@ addLast(value: T): void; | ||
clear(): void; | ||
indexOf(value: T): number; | ||
getFirst(): T | null; | ||
getLast(): T | null; | ||
removeAt(index: number): T | null; | ||
remove(value: T): boolean; | ||
toArray(): T[]; | ||
} | ||
export {}; |
@@ -1,2 +0,9 @@ | ||
import binarySearch from "./Algorithms/binarySearch"; | ||
import binarySearch from "./Algorithms/search/binarySearch"; | ||
import factorial from "./Algorithms/search/factorial"; | ||
import linearSearch from "./Algorithms/search/linearSearch"; | ||
import recursiveBinarySearch from "./Algorithms/search/recursiveBinarySearch"; | ||
import bubbleSort from "./Algorithms/sort/bubbleSort"; | ||
import insertionSort from "./Algorithms/sort/insertionSort"; | ||
import mergeSort from "./Algorithms/sort/mergeSort"; | ||
import quickSort from "./Algorithms/sort/quickSort"; | ||
import DoublyLinkedList from "./dataStructures/DoublyLinkedList"; | ||
@@ -7,2 +14,2 @@ import Queue from "./dataStructures/Queue"; | ||
import Logger from "./lib/Logger"; | ||
export { SingleLinkedList, Stack, Queue, DoublyLinkedList as LinkedList, Logger, binarySearch, }; | ||
export { SingleLinkedList, Stack, Queue, DoublyLinkedList as LinkedList, Logger, binarySearch, factorial, linearSearch, recursiveBinarySearch, bubbleSort, insertionSort, mergeSort, quickSort, }; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
25327
31
723