{"id":18665000,"url":"https://github.com/arnavbee/queues","last_synced_at":"2025-06-27T13:36:15.154Z","repository":{"id":250590764,"uuid":"834865626","full_name":"arnavbee/queues","owner":"arnavbee","description":null,"archived":false,"fork":false,"pushed_at":"2024-08-01T18:43:55.000Z","size":7,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-11T02:05:51.618Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C++","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/arnavbee.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":"2024-07-28T15:45:22.000Z","updated_at":"2024-07-28T17:28:09.000Z","dependencies_parsed_at":"2024-12-27T17:38:09.427Z","dependency_job_id":null,"html_url":"https://github.com/arnavbee/queues","commit_stats":null,"previous_names":["arnavbee/queues"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/arnavbee/queues","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arnavbee%2Fqueues","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arnavbee%2Fqueues/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arnavbee%2Fqueues/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arnavbee%2Fqueues/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/arnavbee","download_url":"https://codeload.github.com/arnavbee/queues/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arnavbee%2Fqueues/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262265917,"owners_count":23284597,"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":"2024-11-07T08:25:50.751Z","updated_at":"2025-06-27T13:36:15.132Z","avatar_url":"https://github.com/arnavbee.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Queue\n\nQueue is the type of data structure used to store data in the form of FIFO(First In First Out)\n\nIt has the same operations as stacks but the first element gets picked out first in the pop operation.\n\n## Implementation Of Queue using Array\n\nclass Queue {\n    public:\n    int size;\n    int *arr;\n    int start;\n    int end;\n\n    int currSize;\n\n    Queue(int s){\n    this -\u003e size = s;\n    arr = new int[size];\n    start = -1;\n    end = -1;\n    currSize = 0;\n    }\n\n\n    void push(int element){\n\n        if(currSize == size) {\n            cout\u003c\u003c\"Stack Overflow\"\u003c\u003cendl;\n        }\n\n    if(currSize == 0){\n     start = 0;\n      end = 0;\n    }\n\n    else {\n        end = (end + 1) % size; // handling the circular nature of the push operation\n    }\n\n    arr[end] = element;\n    currSize++;\n    }\n\n    void pop(){\n    if(currSize == 0){\n        cout\u003c\u003c\"Stack Underflow\"\u003c\u003cendl;\n    }\n\n    if(currSize == 1){\n        start = -1;\n        end = -1;\n    }\n\n    else {\n    start = (start + 1) % size;\n\n    }\n\n     currSize--;\n        \n\n    }\n\n    void top(){\n\n    if(currSize == 0){\n        cout\u003c\u003c\"Stack is empty\"\u003c\u003cendl;\n    }\n        cout\u003c\u003c arr[start]\u003c\u003cendl;\n    }\n\n\n};\n\n\nint main(){\n\n  Queue qt(5);\n\n  qt.push(4);\n  qt.push(5);\n  qt.push(6);\n  qt.push(7);\n\n  qt.top(); // answer is 4\n\n}\n\n\n\n## Implement Stack using Queues\n\n#include\u003ciostream\u003e\n#include\u003cqueue\u003e\n\nclass MyStack {\n    queue\u003cint\u003e qt;\npublic:\n\n\n\n\n    \n    void push(int x) {\n    \n        int s = qt.size();\n\n     \n    qt.push(x);\n\n    for(int i = 0; i \u003c s; ++i){\n        qt.push(qt.front());\n        qt.pop();\n\n    }\n\n\n    \n        \n    }\n    \n    int pop() {\n\n        if (qt.empty()) {\n            return -1; \n        }\n\n    int topElement = qt.front();\n    qt.pop();\n\n    return topElement;\n\n        \n    }\n    \n    int top() {\n\n      if (qt.empty()) {\n         \n            return -1; \n        }\n\n    int topElement =qt.front();\n    return topElement;\n        \n    }\n    \n    bool empty() {\n   return qt.empty();\n    }\n        \n};","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farnavbee%2Fqueues","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Farnavbee%2Fqueues","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farnavbee%2Fqueues/lists"}