{"id":25490177,"url":"https://github.com/fix2015/structure_priority_queue","last_synced_at":"2026-07-22T15:32:22.442Z","repository":{"id":273081552,"uuid":"918654274","full_name":"fix2015/structure_priority_queue","owner":"fix2015","description":"A simple implementation of the **Priority Queue** data structure in JavaScript. This repository demonstrates how to create a priority queue class with essential methods and explains its functionality with practical examples.  ","archived":false,"fork":false,"pushed_at":"2025-01-18T14:08:47.000Z","size":5,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-21T09:54:32.528Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fix2015.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-01-18T14:06:51.000Z","updated_at":"2025-01-18T14:41:21.000Z","dependencies_parsed_at":null,"dependency_job_id":"5e479ff5-066e-497f-9a1f-272a4ad1331c","html_url":"https://github.com/fix2015/structure_priority_queue","commit_stats":null,"previous_names":["fix2015/structure_priority_queue"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/fix2015/structure_priority_queue","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fix2015%2Fstructure_priority_queue","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fix2015%2Fstructure_priority_queue/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fix2015%2Fstructure_priority_queue/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fix2015%2Fstructure_priority_queue/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fix2015","download_url":"https://codeload.github.com/fix2015/structure_priority_queue/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fix2015%2Fstructure_priority_queue/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":35768236,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-07-20T02:08:10.276Z","status":"online","status_checked_at":"2026-07-22T02:00:06.236Z","response_time":124,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2025-02-18T21:27:26.596Z","updated_at":"2026-07-22T15:32:22.427Z","avatar_url":"https://github.com/fix2015.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Priority Queue Data Structure in JavaScript 🚀  \n\nA simple implementation of the **Priority Queue** data structure in JavaScript. This repository demonstrates how to create a priority queue class with essential methods and explains its functionality with practical examples.  \n\n---\n\n## What is a Priority Queue?  \nA **Priority Queue** is a data structure that stores elements in a way that allows efficient access to the element with the highest priority. Each element in the queue is assigned a priority value, and elements with higher priority are dequeued before elements with lower priority. Priority queues are commonly implemented using heaps.  \n\n---\n\n## Features  \n- **Enqueue**: Add an element to the queue with a given priority.  \n- **Dequeue**: Remove and return the element with the highest priority.  \n- **Peek**: View the element with the highest priority without removing it.  \n- **isEmpty**: Check if the queue is empty.  \n- **Size**: Get the number of elements in the queue.  \n\n---\n\n## Code Implementation  \n\nHere’s the JavaScript implementation of the priority queue:  \n\n```javascript\nclass PriorityQueue {\n    constructor() {\n        this.queue = [];\n    }\n\n    // Add an element to the queue with a given priority\n    enqueue(element, priority) {\n        const item = { element, priority };\n        if (this.isEmpty()) {\n            this.queue.push(item);\n        } else {\n            let added = false;\n            for (let i = 0; i \u003c this.queue.length; i++) {\n                if (item.priority \u003e this.queue[i].priority) {\n                    this.queue.splice(i, 0, item);\n                    added = true;\n                    break;\n                }\n            }\n            if (!added) {\n                this.queue.push(item);\n            }\n        }\n    }\n\n    // Remove and return the element with the highest priority\n    dequeue() {\n        if (this.isEmpty()) {\n            return \"Queue is empty!\";\n        }\n        return this.queue.shift();\n    }\n\n    // View the element with the highest priority without removing it\n    peek() {\n        if (this.isEmpty()) {\n            return \"Queue is empty!\";\n        }\n        return this.queue[0];\n    }\n\n    // Check if the queue is empty\n    isEmpty() {\n        return this.queue.length === 0;\n    }\n\n    // Get the size of the queue\n    size() {\n        return this.queue.length;\n    }\n}\n```\n\n---\n\n## Example Usage  \n\n```javascript\n// Initialize the priority queue\nconst pq = new PriorityQueue();\n\n// Enqueue elements with priorities\npq.enqueue(\"Task 1\", 1);\npq.enqueue(\"Task 2\", 3);\npq.enqueue(\"Task 3\", 2);\n\n// Peek at the highest priority element\nconsole.log(pq.peek()); // Output: { element: 'Task 2', priority: 3 }\n\n// Dequeue elements\nconsole.log(pq.dequeue()); // Output: { element: 'Task 2', priority: 3 }\nconsole.log(pq.dequeue()); // Output: { element: 'Task 3', priority: 2 }\n\n// Check if the queue is empty\nconsole.log(pq.isEmpty()); // Output: false\n\n// Get the size of the queue\nconsole.log(pq.size()); // Output: 1\n```\n\n---\n\n## Real-World Applications  \n1. **Task Scheduling**: Managing tasks based on priority in operating systems.  \n2. **Dijkstra's Algorithm**: Finding the shortest path in graphs.  \n3. **Job Scheduling**: For scheduling jobs with different priorities in computers.  \n4. **Bandwidth Management**: Prioritizing network traffic based on importance.  \n\n---\n\n## TikTok Tutorial 🎥  \nWant to see a quick tutorial on how to build this? Check out this TikTok video:  \n[]()  \n\n---\n\n## How to Run the Code  \n1. Clone the repository:  \n   ```bash\n   git clone https://github.com/fix2015/structure_priority_queue\n   cd structure_priority_queue\n   ```\n2. Open the file `index.js` in your favorite code editor.  \n3. Run the file using Node.js:  \n   ```bash\n   node index.js\n   ```\n\n---\n\n## Contributing  \nContributions are welcome! If you have suggestions or want to add new features, feel free to create a pull request.  \n\n---\n\n## License  \nThis project is licensed under the MIT License.  \n\n---\n\n## Connect with Me:\n- [LinkedIn - Vitalii Semianchuk](https://www.linkedin.com/in/vitalii-semianchuk-9812a786/)\n- [Telegram - @jsmentorfree](https://t.me/jsmentorfree) - We do a lot of free teaching on this channel! Join us to learn and grow in web development.\n- [Tiktok - @jsmentoring](https://www.tiktok.com/@jsmentoring) Everyday new videos\n- [Youtube - @jsmentor-uk](https://www.youtube.com/@jsmentor-uk) Mentor live streams\n- [Dev.to - fix2015](https://dev.to/fix2015) Javascript featured, live, experience but about Priority Queue\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffix2015%2Fstructure_priority_queue","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffix2015%2Fstructure_priority_queue","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffix2015%2Fstructure_priority_queue/lists"}