Skip to content

Linked list stack implemented #139

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 19 commits into from
Closed

Linked list stack implemented #139

wants to merge 19 commits into from

Conversation

HarsheetKakar
Copy link
Contributor

References to other Issues or PRs or Relevant literature

Fixes #113

Brief description of what is fixed or changed

LinkedListStack implemented with relevant tests

Other comments

@codecov
Copy link

codecov bot commented Mar 11, 2020

Codecov Report

Merging #139 into master will decrease coverage by 0.13%.
The diff coverage is 97.356%.

@@              Coverage Diff              @@
##            master      #139       +/-   ##
=============================================
- Coverage   98.173%   98.042%   -0.131%     
=============================================
  Files           21        21               
  Lines         1588      1635       +47     
=============================================
+ Hits          1559      1603       +44     
- Misses          29        32        +3
Impacted Files Coverage Δ
pydatastructs/graphs/algorithms.py 100% <ø> (ø) ⬆️
pydatastructs/trees/space_partitioning_trees.py 97.619% <ø> (ø) ⬆️
pydatastructs/trees/binary_trees.py 96.894% <ø> (ø) ⬆️
...datastructs/miscellaneous_data_structures/stack.py 94.047% <93.617%> (-0.825%) ⬇️
pydatastructs/trees/heaps.py 98.333% <98.333%> (+0.018%) ⬆️

Impacted file tree graph

@czgdp1807
Copy link
Member

Can you please merge the latest master into your LinkedListStack branch?

Comment on lines 124 to 125
obj.front = obj.stack.head
obj.tail = obj.stack.tail
Copy link
Member

Choose a reason for hiding this comment

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

IMO, only obj.top should suffice and that too as a @property and not as a separate attribute.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

peek property is essentially doing the same.

Comment on lines +137 to +138
else:
raise TypeError("Expected type: list/tuple")
Copy link
Member

Choose a reason for hiding this comment

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

Please do input filtering at the entry point of a function/method.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I moved refactored the new method, check it its good enough

Comment on lines +135 to +136
else:
raise TypeError("Expected %s but got %s"%(obj._dtype, type(x)))
Copy link
Member

Choose a reason for hiding this comment

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

+1

Comment on lines +162 to +163
def is_empty(self):
return self.size == 0
Copy link
Member

Choose a reason for hiding this comment

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

Can we use, self.top here to figure out whether the stack is empty?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It will lose consistency with LinkedListQueue if i change it.

Copy link
Member

Choose a reason for hiding this comment

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

It looks like that LinkedListQueue needs some changes in it's __new__ method. Can you please address similar comments there as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure will solve it in different PR.

Comment on lines 87 to 89
else:
if not all(map(lambda x: _check_type(x, TreeNode), elements)):
raise ValueError("Expect a list/tuple of TreeNode got %s"%(elements))
Copy link
Member

Choose a reason for hiding this comment

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

Master should be merged as these changes are already there.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thats a mess, I will remove them

Comment on lines 51 to 57
non_TreeNode_elements = [
(7, 7), TreeNode(25, 25), TreeNode(100, 100),
TreeNode(1, 1), (2, 2), TreeNode(3, 3),
TreeNode(17, 17), TreeNode(19, 19), TreeNode(36, 36)
]
assert raises(ValueError, lambda:
BinaryHeap(elements = non_TreeNode_elements, heap_property='min'))
Copy link
Member

Choose a reason for hiding this comment

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

+1

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it broke the code when i removed those 2 files, idk why it is still showing up, any suggestions?

@czgdp1807
Copy link
Member

Please resolve the conflicts.

if len(items) != 0 and dtype is NoneType:
obj._dtype = type(items[0])
for x in items:
if type(x) == obj._dtype:
Copy link
Member

Choose a reason for hiding this comment

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

Is it possible to use _check_type from misc_utils.py here?

@czgdp1807
Copy link
Member

I just observed that some changes are needed in LinkedListQueue as well as LinkedListStack to allow data of different data types.
Can you please make a different PR for fixing LinkedListQueue. Keep this open, first we will merge the queue PR and then this one? Apologies for inconveniences.

@HarsheetKakar
Copy link
Contributor Author

I just observed that some changes are needed in LinkedListQueue as well as LinkedListStack to allow data of different data types.
Can you please make a different PR for fixing LinkedListQueue. Keep this open, first we will merge the queue PR and then this one? Apologies for inconveniences.

This PR has already very messy, I will fork it again and make a bit better one. Just started using git for big projects, sorry for making a mess.

@HarsheetKakar
Copy link
Contributor Author

shall I create 2 different PRs one for queue and one for stack?

@czgdp1807
Copy link
Member

If you are going to close it then first make a PR for fixing LinkedListQueue and then after it's merged, make one for LinkedListStack.
P.S. - It's completely fine to mess things up, at least it shows you are putting in efforts. :-)

@HarsheetKakar HarsheetKakar deleted the LinkedListStack branch March 13, 2020 17:37
@HarsheetKakar HarsheetKakar mentioned this pull request Mar 13, 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.

Linked list implementation of stack and queue data structure
4 participants