codezonediitj / pydatastructs

A python package for data structures and algorithms
https://pydatastructs.readthedocs.io/en/stable/
Other
202 stars 270 forks source link

Added Deque - Array #321

Closed Arvind-raj06 closed 3 years ago

Arvind-raj06 commented 3 years ago

Array Deque

References to other Issues or PRs or Relevant literature

"Fixes #120". See https://github.com/codezonediitj/pydatastructs/issues/120

Brief description of what is fixed or changed

Added Array deque with DODA and created a abstract class for Deque

Other comments

Hope this code works fine and if there is any issue ping me, yes this PR also included the SWOC participation

codecov[bot] commented 3 years ago

Codecov Report

Merging #321 (b2e588c) into master (09b338c) will decrease coverage by 0.271%. The diff coverage is 86.764%.

@@              Coverage Diff              @@
##            master      #321       +/-   ##
=============================================
- Coverage   98.828%   98.557%   -0.272%     
=============================================
  Files           25        25               
  Lines         3073      3119       +46     
=============================================
+ Hits          3037      3074       +37     
- Misses          36        45        +9     
Impacted Files Coverage Δ
...datastructs/miscellaneous_data_structures/queue.py 95.982% <86.764%> (-4.018%) :arrow_down:

Impacted file tree graph

czgdp1807 commented 3 years ago

What's the difference between queue or doubly-ended queue other than the difference in end points for adding or removing elements?

Arvind-raj06 commented 3 years ago

It can work like a stack and doubly linked list if used in a way but the queue's cannot

Arvind-raj06 commented 3 years ago

I have implemented it only for array and yet to be in linked list....

czgdp1807 commented 3 years ago

In other words, can we make queue doubly ended? Do we need an extra class like, Deque? Can we just simply add methods like, appendleft and popleft to queue class? What will be the disadvantages of adapting such approaches?

Arvind-raj06 commented 3 years ago

But as per people's knowledge the queue will always insert at end and remove at front but deque will have insert and delete at both sides, that's the reason they call it double ended queue.

czgdp1807 commented 3 years ago

What about adding an extra argument, double_ended in the constructor of queue? If it is True, only then, appendleft and popright will work, otherwise these both will raise error.

Arvind-raj06 commented 3 years ago

Yeah that can work too

Arvind-raj06 commented 3 years ago

But I need to reframe the rear pointer to work for both double ended queue and regular queue if that's ok I will proceed doing changes with commit.

czgdp1807 commented 3 years ago

You can try changes with queue. But do not delete ArrayDeque in your work branch for this PR in case we don't go with changes in queue.

Arvind-raj06 commented 3 years ago

Cool I will complete it right away and show it you

Arvind-raj06 commented 3 years ago

@czgdp1807 Now will this work!?

czgdp1807 commented 3 years ago

You can remove the Deque class.

Arvind-raj06 commented 3 years ago

You can remove the Deque class.

Yes

Arvind-raj06 commented 3 years ago

@czgdp1807 Done

czgdp1807 commented 3 years ago

Please make similar changes for LinkedListQueue and remaining implementations of queues.

Arvind-raj06 commented 3 years ago

Please make similar changes for LinkedListQueue and remaining implementations of queues.

Yeah sure

@czgdp1807 I have a doubt in implementing the above in priority queue what should I name the operation as but in wikipedia it's given as https://en.wikipedia.org/wiki/Double-ended_priority_queue#Operations

czgdp1807 commented 3 years ago

PriorityQueue isn' t a queue as far as I remember. The double ended property should only be added to the sub classes of Queue.

Arvind-raj06 commented 3 years ago

@czgdp1807 I did some improvements on suffix tree, it's working quite fine and shall I make the PR after this or now!

czgdp1807 commented 3 years ago

it's working quite fine and shall I make the PR after this or now!

Sure.

Arvind-raj06 commented 3 years ago

it's working quite fine and shall I make the PR after this or now!

Sure.

Yeah