Skip to content

[WIP] Added Stacks Using Linked List #121

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 11 commits into from
Closed

[WIP] Added Stacks Using Linked List #121

wants to merge 11 commits into from

Conversation

sarthakforwet
Copy link

References to other Issues or PRs or Relevant literature

Issue #113

Brief description of what is fixed or changed

I have added linked list implementation of Stacks and working on Linked list implementation of queues as well .

Other comments

@czgdp1807
Copy link
Member

Please allow edits from maintainers. See the check box on the right side of the page. Just tick it.

@sarthakforwet
Copy link
Author

@czgdp1807 How to know on what basis and what is being checked ?
Thank you

@czgdp1807
Copy link
Member

czgdp1807 commented Mar 3, 2020

@sarthakforwet
I have removed build and dist files from your branch, developer. Please do the following before pushing any commit,

  1. git remote add origin_user https://github.com/sarthakforwet/pydatastructs
  2. git pull origin_user developer
  3. sudo python3 setup.py develop(if you are on linux or something equivalent for windows).
  4. Add your commits
  5. Push to your branch.

Let me know if you face any problems.

@@ -12,7 +12,7 @@ appearance, race, religion, or sexual identity and orientation.
## Our Standards

Examples of behavior that contributes to creating a positive environment
include:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't make changes to this file.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please address this.

return self.data

def peek(self):
return self.top.data
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a new line.


# A class to implement Stacks Built over Singly Linked Lists

def __init__(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use a __new__ method.

@@ -0,0 +1,24 @@
from pydatastructs import SinglyLinkedList

class Linked_Stacks:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A better name is LinkedListStack.

@czgdp1807
Copy link
Member

Please shift the code to stacks.py in miscellaneous_data_structures.

@sarthakforwet
Copy link
Author

Okk I understood the points and also shifted my code to stacks.py file .

@codecov
Copy link

codecov bot commented Mar 4, 2020

Codecov Report

Merging #121 into master will decrease coverage by 1.494%.
The diff coverage is 25.641%.

@@             Coverage Diff              @@
##           master      #121       +/-   ##
============================================
- Coverage   97.94%   96.446%   -1.495%     
============================================
  Files          20        21        +1     
  Lines        1311      1632      +321     
============================================
+ Hits         1284      1574      +290     
- Misses         27        58       +31
Impacted Files Coverage Δ
...datastructs/miscellaneous_data_structures/stack.py 60.256% <25.641%> (-34.616%) ⬇️
pydatastructs/trees/binary_trees.py 96.894% <0%> (-0.271%) ⬇️
pydatastructs/graphs/graph.py 100% <0%> (ø) ⬆️
pydatastructs/trees/space_partitioning_trees.py 97.619% <0%> (ø) ⬆️
pydatastructs/graphs/__init__.py 100% <0%> (ø) ⬆️
pydatastructs/trees/__init__.py 100% <0%> (ø) ⬆️
pydatastructs/linear_data_structures/__init__.py 100% <0%> (ø) ⬆️
pydatastructs/__init__.py 100% <0%> (ø) ⬆️
...datastructs/linear_data_structures/linked_lists.py 100% <0%> (ø) ⬆️
pydatastructs/graphs/algorithms.py 100% <0%> (ø)
... and 3 more

Impacted file tree graph

@sarthakforwet
Copy link
Author

@czgdp1807 Changes have been made and sucessful so should I close this issue now?

@czgdp1807
Copy link
Member

Please keep the issue open until the PR is merged.


class Linked_Stacks(Stack):

"""Representation of Stack Data Structure using Doubly Linked List
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO, we can use SinglyLinkedList for stacks.

def peek(self):
if self.top is not None:
return self.top.data
return "Stack is empty"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead raise a ValueError.

Comment on lines 177 to 182
def __str__(self):
"Used for Printing the Stack"
iterator = self.top
while iterator is not None:
print(iterator.data)
iterator = iterator.next
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid print statements. Instead return a string.

self.top = self.top.prev
return self.data
else:
raise ValueError
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not necessary though.

@czgdp1807
Copy link
Member

Closing in favour of #152

@czgdp1807 czgdp1807 closed this Mar 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants