{"id":25490173,"url":"https://github.com/fix2015/structure_deque","last_synced_at":"2025-11-08T12:30:34.978Z","repository":{"id":273082819,"uuid":"918659116","full_name":"fix2015/structure_deque","owner":"fix2015","description":"A simple implementation of the **Deque** (Double-Ended Queue) data structure in JavaScript. This repository demonstrates how to create a deque class with essential methods and explains its functionality with practical examples.  ","archived":false,"fork":false,"pushed_at":"2025-01-18T14:23:03.000Z","size":7,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-18T15:29:23.423Z","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:20:39.000Z","updated_at":"2025-01-18T14:41:17.000Z","dependencies_parsed_at":"2025-01-18T15:39:39.210Z","dependency_job_id":null,"html_url":"https://github.com/fix2015/structure_deque","commit_stats":null,"previous_names":["fix2015/structure_deque"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fix2015%2Fstructure_deque","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fix2015%2Fstructure_deque/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fix2015%2Fstructure_deque/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fix2015%2Fstructure_deque/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fix2015","download_url":"https://codeload.github.com/fix2015/structure_deque/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239552863,"owners_count":19658003,"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":[],"created_at":"2025-02-18T21:27:26.097Z","updated_at":"2025-11-08T12:30:34.931Z","avatar_url":"https://github.com/fix2015.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Deque Data Structure in JavaScript 🚀  \n\nA simple implementation of the **Deque** (Double-Ended Queue) data structure in JavaScript. This repository demonstrates how to create a deque class with essential methods and explains its functionality with practical examples.  \n\n---\n\n## What is a Deque?  \nA **Deque** (Double-Ended Queue) is a linear data structure that allows elements to be added or removed from both ends—front and back. It is a generalization of a queue, where elements can be inserted or removed from either end, making it more versatile than a standard queue.  \n\n---\n\n## Features  \n- **InsertFront**: Add an element to the front of the deque.  \n- **InsertBack**: Add an element to the back of the deque.  \n- **RemoveFront**: Remove and return the element from the front.  \n- **RemoveBack**: Remove and return the element from the back.  \n- **PeekFront**: View the element at the front without removing it.  \n- **PeekBack**: View the element at the back without removing it.  \n- **Size**: Get the number of elements in the deque.  \n- **isEmpty**: Check if the deque is empty.  \n\n---\n\n## Code Implementation  \n\nHere’s the JavaScript implementation of the deque:  \n\n```javascript\nclass Deque {\n    constructor() {\n        this.items = [];\n    }\n\n    // Add an element to the front of the deque\n    insertFront(element) {\n        this.items.unshift(element);\n    }\n\n    // Add an element to the back of the deque\n    insertBack(element) {\n        this.items.push(element);\n    }\n\n    // Remove and return the element from the front of the deque\n    removeFront() {\n        if (this.isEmpty()) {\n            return \"Deque is empty!\";\n        }\n        return this.items.shift();\n    }\n\n    // Remove and return the element from the back of the deque\n    removeBack() {\n        if (this.isEmpty()) {\n            return \"Deque is empty!\";\n        }\n        return this.items.pop();\n    }\n\n    // Peek at the element at the front without removing it\n    peekFront() {\n        if (this.isEmpty()) {\n            return \"Deque is empty!\";\n        }\n        return this.items[0];\n    }\n\n    // Peek at the element at the back without removing it\n    peekBack() {\n        if (this.isEmpty()) {\n            return \"Deque is empty!\";\n        }\n        return this.items[this.items.length - 1];\n    }\n\n    // Get the size of the deque\n    size() {\n        return this.items.length;\n    }\n\n    // Check if the deque is empty\n    isEmpty() {\n        return this.items.length === 0;\n    }\n}\n```\n\n---\n\n## Example Usage  \n\n```javascript\n// Initialize the deque\nconst deque = new Deque();\n\n// Insert elements at the front and back\ndeque.insertFront(10);\ndeque.insertBack(20);\ndeque.insertFront(5);\n\n// Peek at the front and back elements\nconsole.log(deque.peekFront()); // Output: 5\nconsole.log(deque.peekBack());  // Output: 20\n\n// Remove elements from the front and back\nconsole.log(deque.removeFront()); // Output: 5\nconsole.log(deque.removeBack());  // Output: 20\n\n// Get the size of the deque\nconsole.log(deque.size()); // Output: 1\n\n// Check if the deque is empty\nconsole.log(deque.isEmpty()); // Output: false\n```\n\n---\n\n## Real-World Applications  \n1. **Task Scheduling**: Used in round-robin scheduling for managing tasks.  \n2. **Sliding Window Algorithms**: Efficiently processing a range of elements in an array or list.  \n3. **Palindrome Checker**: Checking if a string is a palindrome by comparing characters from both ends.  \n4. **Deque-based Buffer**: Implementing a buffer where data can be inserted and removed from both ends.  \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_deque\n   cd structure_deque\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 Deque\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffix2015%2Fstructure_deque","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffix2015%2Fstructure_deque","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffix2015%2Fstructure_deque/lists"}