-
Notifications
You must be signed in to change notification settings - Fork 313
[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
Conversation
Please allow edits from maintainers. See the check box on the right side of the page. Just tick it. |
@czgdp1807 How to know on what basis and what is being checked ? |
@sarthakforwet
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: |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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
.
Please shift the code to |
Okk I understood the points and also shifted my code to |
Codecov Report
@@ 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
|
@czgdp1807 Changes have been made and sucessful so should I close this issue now? |
Please keep the issue open until the PR is merged. |
|
||
class Linked_Stacks(Stack): | ||
|
||
"""Representation of Stack Data Structure using Doubly Linked List |
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead raise a ValueError
.
def __str__(self): | ||
"Used for Printing the Stack" | ||
iterator = self.top | ||
while iterator is not None: | ||
print(iterator.data) | ||
iterator = iterator.next |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ValueError takes a string argument: https://kite.com/python/answers/how-to-raise-a-valueerror-in-python
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not necessary though.
Closing in favour of #152 |
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