leetcode

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit de779636db17281e0d23219f39b5b99988394aa2
parent 75c8ee4c64ebd40cb877e3a14da7a0e8b48c7a93
Author: AndrewLockVI <andrewlaack1@gmail.com>
Date:   Sat,  8 Apr 2023 23:01:54 -0500

Doubly linked list queue

Diffstat:
Aimplement-queue/a.out | 0
Aimplement-queue/implement-queue.cpp | 59+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 59 insertions(+), 0 deletions(-)

diff --git a/implement-queue/a.out b/implement-queue/a.out Binary files differ. diff --git a/implement-queue/implement-queue.cpp b/implement-queue/implement-queue.cpp @@ -0,0 +1,59 @@ +#include <list> +#include <iostream> + + + + + + +using namespace std; + + +//Leet Ratings +// Speed Memory +//Total 2ms 7MB +//Beats 43.74% 45.49% +//Impletmentation of a queue class using a doubly linked list. + +class MyQueue { +public: + list<int> sl = {}; + + void push(int x) { + sl.push_front(x); + } + +int pop() { + if (sl.size() != 0) { + int value = sl.back(); + sl.pop_back(); + return value; + } else { + return pop(); + } +} + + int peek() { + return sl.back(); + } + + bool empty() { + return sl.empty(); + } +}; + + + + + +int main(){ + auto queue = MyQueue(); + queue.push(10); + cout << queue.pop() << endl; + queue.push(13); + queue.push(124); + cout << queue.empty() << endl; + cout << queue.pop() << endl; + + +}