{"id":23634797,"url":"https://github.com/ahmedgaafer/ts-data-structures","last_synced_at":"2026-01-29T06:32:16.110Z","repository":{"id":57095671,"uuid":"189640160","full_name":"ahmedgaafer/TS-Data-Structures","owner":"ahmedgaafer","description":"A lightweight TS data structures package","archived":false,"fork":false,"pushed_at":"2023-10-18T13:14:49.000Z","size":3559,"stargazers_count":1,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-18T22:42:20.405Z","etag":null,"topics":["data-structures","graph","heap","javascript","javascript-library","stack","typescript","typescript-library"],"latest_commit_sha":null,"homepage":"https://ahmedgaafer.github.io/TS-Data-Structures/","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ahmedgaafer.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-05-31T18:25:56.000Z","updated_at":"2022-11-12T12:11:53.000Z","dependencies_parsed_at":"2023-02-06T08:17:14.056Z","dependency_job_id":null,"html_url":"https://github.com/ahmedgaafer/TS-Data-Structures","commit_stats":null,"previous_names":["ahmedgaafer/js-data-structures"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahmedgaafer%2FTS-Data-Structures","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahmedgaafer%2FTS-Data-Structures/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahmedgaafer%2FTS-Data-Structures/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahmedgaafer%2FTS-Data-Structures/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ahmedgaafer","download_url":"https://codeload.github.com/ahmedgaafer/TS-Data-Structures/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239565650,"owners_count":19660154,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["data-structures","graph","heap","javascript","javascript-library","stack","typescript","typescript-library"],"created_at":"2024-12-28T05:19:49.856Z","updated_at":"2025-11-08T22:30:31.916Z","avatar_url":"https://github.com/ahmedgaafer.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# TypeScript Data Structures\n\n\u003cp align=\"\"\u003e\n  \u003ca href=\"https://www.npmjs.com/package/@ahmeds.gaafer/ts-data-structures\" target=\"_blank\"\u003e\u003cimg src=\"https://img.shields.io/npm/l/@ahmeds.gaafer/ts-data-structures\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://www.npmjs.com/package/@ahmeds.gaafer/ts-data-structures\" target=\"_blank\"\u003e\u003cimg src=\"https://img.shields.io/bundlephobia/min/@ahmeds.gaafer/ts-data-structures\" \u003e\u003c/a\u003e\n  \u003ca href=\"https://codeclimate.com/github/ahmedgaafer/TS-Data-Structures\"\u003e\u003cimg src=\"https://img.shields.io/codeclimate/maintainability-percentage/ahmedgaafer/TS-Data-Structures\"\u003e\u003c/a\u003e\n \n  \u003ca href=\"#\"\u003e \u003cimg src=\"https://img.shields.io/badge/testing-true-green\"\u003e \u003c/a\u003e\n\u003c/p\u003e  \n\u003cp align=\"\"\u003e\n  \u003ca href=\"https://discord.gg/TgVpvUN\" target=\"_blank\"\u003e\u003cimg src=\"https://img.shields.io/discord/712223278844084275?label=Discord\u0026style=for-the-badge\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\nData Structures package made by TypeScript.\n\n## Install\n\n```bash\n$ npm i @ahmeds.gaafer/ts-data-structures\n```\n\n## Data Structure list:\n\n- [x] Singly Linked List\n- [x] Doubly Linked List\n- [x] Queue\n- [x] Stack\n- [x] Heap\n- [x] Graph\n\n## Usage\n\n### Singly Linked List:\n\n```ts\nimport { SinglyLinkedList } from \"@ahmeds.gaafer/ts-data-structures\";\n\n// The constructor can accept an array as an input and it will transform the array to the linked list\nconst arr = [1, 2, 3];\nconst list = new SinglyLinkedList\u003cnumber\u003e(arr);\n\nlist.push(1);\n\nlist.view();\n\n// You can chain methods that does not return a value\n\nlist.popStart().pop().view(); // vaild\n\nlist.getHead().view(); // invalid\n```\n\nfunctions:\n\n- **_.insert(data, pos)_** =\u003e Insert data to certian position.\n- **_.pushStart(data)_** =\u003e Insert data at the head position.\n- **_.push(data)_** =\u003e Insert data at tail position.\n- **_.delete(pos)_** =\u003e Delete element at a certian position.\n- **_.pop()_** =\u003e Delete element from the end of the tail.\n- **_.popStart()_** =\u003e Delte element from the head.\n- **_.getHead()_** =\u003e Returns a copy of the head node.\n- **_.getTail()_** =\u003e Returns a copy of the tail node.\n- **_.view()_** =\u003e Prints a visual dispaly of the linked list.\n- **_.toArray()_** =\u003e Returns the linked list as an array\n\n### Doubly Linked List:\n\n```ts\nimport { DoublyLinkedList } from \"@ahmeds.gaafer/ts-data-structures\";\n// The constructor can accept an array as an input and it will transform the array to the linked list\nconst arr = [1, 2, 3];\nconst list = new DoublyLinkedList\u003cnumber\u003e(arr);\n\nlist.push(1);\n\nlist.view();\n\n// You can chain methods that does not return a value\n\nlist.popStart().pop().view(); // vaild\n\nlist.getHead().view(); // invalid\n```\n\nfunctions:\n\n- **_.insert(data, pos)_** =\u003e Insert data to certian position.\n- **_.pushStart(data)_** =\u003e Insert data at the head position.\n- **_.push(data)_** =\u003e Insert data at tail position.\n- **_.delete(pos)_** =\u003e Delete element at a certian position.\n- **_.pop()_** =\u003e Delete element from the end of the tail.\n- **_.popStart()_** =\u003e Delte element from the head.\n- **_.getHead()_** =\u003e Returns a copy of the head node.\n- **_.getTail()_** =\u003e Returns a copy of the tail node.\n- **_.view()_** =\u003e Prints a visual dispaly of the linked list.\n- **_.toArray()_** =\u003e Returns the linked list as an array.\n\n### Queue:\n\n```ts\nimport { Queue } from \"@ahmeds.gaafer/ts-data-structures\";\n\n// The constructor can accept an array as an input and it will transform the array to the Queue\nconst arr = [1, 2, 3];\nconst queue = new Queue\u003cnumber\u003e(arr);\n\nqueue.enqueue(5);\nqueue.deqeue();\n\n// You can chain methods that does not return a value\nqueue.enqueue(5).dequeue().view(); //vaild\n\nqueue.peak().view(); // invalid\n```\n\nfunctions:\n\n- **_.enqueue(data)_** =\u003e Add data to the end of the queue.\n- **_.dequeue()_** =\u003e Remove first element of the queue.\n- **_.peak()_** =\u003e Returns the first element in the queue.\n- **_.getSize()_** =\u003e Returns the size of the queue.\n- **_.view()_** =\u003e Prints a visual dispaly of the queue.\n\n### Stack:\n\n```ts\nimport { Stack } from \"@ahmeds.gaafer/ts-data-structures\";\n\n// The constructor can accept an array as an input and it will transform the array to the Heap\n\nconst arr = [1, 2, 3];\n\nconst stack = new Stack\u003cnumber\u003e(arr);\n\nstack.push(1);\n\n// You can chain methods that does not return a value\nstack.push(1).push(2).pop(); // vaild\nstack.peak().push(1); // invalid\n```\n\nfunctions:\n\n- **_.push(data)_** =\u003e Inserts data to top of stack.\n- **_.pop()_** =\u003e Removes the item on the top of the stack.\n- **_.peak()_** =\u003e Returns the item on the top of the stack.\n- **_.getSize()_** =\u003eReturns the size of the stack;\n- **_.view()_** =\u003e Prints a visual display of the stack.\n\n### Heap:\n\n```ts\nimport { Heap } from \"@ahmeds.gaafer/ts-data-structures\";\n\n// The constructor can accept an array as an input and it will transform the array to the Heap\n\nconst arr = [1, 2, 3];\nconst maxHeapOptions = {\n  cmp: (a, b) =\u003e a \u003c b;\n}\nconst minHeapOptions = {\n  cmp: (a, b) =\u003e a \u003e b;\n}\n\n// Heap type is set to number by default but you can change it\n\n//min heap\nconst minHeap = new Heap(arr, minHeapOptions);\n\n//max heap\nconst maxHeap = new Heap(arr, maxHeapOptions);\n\n/// or\nconst maxHeap = new Heap\u003cstring\u003e([], maxHeapOptions);\n\nmaxHeap.push(5);\n\n// You can chain methods that does not return a value\nminHeap.push(1).push(2); // vaild\nminHeap.peak().push(1); // invalid\n```\n\nfunctions:\n\n- **_.push(data)_** =\u003e Insert a data to the heap.\n- **_.pop()_** =\u003e Removes the root of the heap and fixes the the heap.\n- **_.peak()_** =\u003e Returns the value of the root of the heap.\n- **_.getSize()_** =\u003e Returns the size of the heap;\n- **_.view()_** =\u003e Prints the array of the heap;\n\n### Graph:\n\n```ts\nimport { Graph } from \"@ahmeds.gaafer/ts-data-structures\";\n\n//The graph can has 2 arguments that are set to false by default.\n//The first argument is \"isUniDirectional\" if you set it to true the graph will be a directed graph.\n//The second argument is \"isWeighted\" if you set it to true the graph will be weighted.\n\nconst g = new Graph(); // un-directed un-weighted graph\n//or\nconst g = new Graph(true, false); // directed un-weighted graph.\n//or\nconst g = new Graph(false, true); // un-directed  weighted graph.\n//or\nconst g = new Graph(true, true); // directed weighted graph\n\ng.addVertex(1);\ng.addVertex(2);\n\n// You can chain methods that does not return a value\n\ng.addVertex(1).addVertex(2); // valid\n\ng.getNeighbors(1).addVertex(3); // invalid\n\ng.removeVertex(5); // remove a non-existent vertex\n\n// etc...\n```\n\nfunctions:\n\n- **_.addVertex(v)_** =\u003e Adds vertex to the graph.\n- **_.addEdge(u, v, w: conditional)_** =\u003e Add edge between vertex \"u\" and vertex \"v\" . weight of the edge \"w\" is valid if only the graph is set to be weighted.\n- **_.removeVertex(v)_** =\u003e Removes the vertex from the graph and removes all of the linked edges to it.\n- **_.removeEdge(u, v)_** =\u003e Removes edge between vertex \"u\" and \"v\".\n- **_.getVerticesNumbers()_** =\u003e Returns the number of vertices in the Graph.\n- **_.getNeighbors(v)_** =\u003e Returns a the list of neighbors of vertex v\n- **_.view()_** =\u003e Display a visual display of the graphs adjacency list.\n\n# Important Note:\n\n\u003e **_Any usage of the functions not mentioned in the functions above might lead to un-expected behavior and may lead to the functions throwing an error._**\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fahmedgaafer%2Fts-data-structures","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fahmedgaafer%2Fts-data-structures","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fahmedgaafer%2Fts-data-structures/lists"}