Implemented most useful and important Data Structures used in Software Development, All With TypeScript ๐
- Linked Lists
- Simple Linked List
- Doubly Linked Lists
- Stacks
- Queues
- Trees
the benefits of using the Type system from TypeScript is the ability to create new types alongside the class definitions, which allows you to implement the Data Structure types easily and correctly.
I've tried to be as close as possible to the real use cases of Data Structures in Real life and in the classic definitions.
here's a quick type definition of Linked List.
type LinkedListType = {
length: number;
head: NodeType | null;
tail: NodeType | null;
push?(value: any): LinkedListType;
pop?(): NodeType | unknown;
shift?(): NodeType | unknown;
unshift?(value: any): LinkedListType;
get?(index: number): NodeType | unknown;
set?(index: number, value: any): boolean;
insert?(index: number, value: any): void;
remove?(value: any): NodeType | unknown;
reverse?(): void;
log?(): void;
};
you can see that each property or method has a declared type. the value
of a linked list however can be different, thats why any
would make sense. A Generic type will be implemented soon.
You can run the example and testing files with this command:
npm run examples
To compile the project, simply run:
npm run build
Run tests with npm test
.
Each Test file is related to one data structure(each file for subgroups) the goal of the unit testing files is to assert the correctness of the implemented Data Structure. you can find tests in the tests Directory.
This repo is under MIT License
Happy Hacking ๐ฅท