Skip to content

Create priority_queue_using_list.py #2428

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 10 commits into from

Conversation

Ashley-J-George
Copy link
Contributor

@Ashley-J-George Ashley-J-George commented Sep 14, 2020

Implementation of Priority Queue using lists

Describe your change:

  • Add an algorithm?
  • Fix a bug or typo in an existing algorithm?
  • Documentation change?

Checklist:

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized.
  • I know that pull requests will not be merged if they fail the automated tests.
  • This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
  • All new Python files are placed inside an existing directory.
  • All filenames are in all lowercase characters with no spaces or dashes.
  • All functions and variable names follow Python naming conventions.
  • All function parameters and return values are annotated with Python type hints.
  • All functions have doctests that pass the automated testing.
  • All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation.
  • If this pull request resolves one or more open issues then the commit message contains Fixes: #{$ISSUE_NO}.

Implementation of Priority Queue using lists
Corrected the spelling mistake of fashion
@TravisBuddy
Copy link

Hey @Ashley-J-George,
Something went wrong with the build.

TravisCI finished with status errored, which means the build failed because of something unrelated to the tests, such as a problem with a dependency or the build process itself.

View build log

TravisBuddy Request Identifier: 820319e0-f6bb-11ea-afed-a1bc0e34d213

@TravisBuddy
Copy link

Hey @Ashley-J-George,
Something went wrong with the build.

TravisCI finished with status errored, which means the build failed because of something unrelated to the tests, such as a problem with a dependency or the build process itself.

View build log

TravisBuddy Request Identifier: ecb0abe0-f6bb-11ea-afed-a1bc0e34d213

@TravisBuddy
Copy link

Hey @Ashley-J-George,
Something went wrong with the build.

TravisCI finished with status errored, which means the build failed because of something unrelated to the tests, such as a problem with a dependency or the build process itself.

View build log

TravisBuddy Request Identifier: 6c3441b0-f6bc-11ea-afed-a1bc0e34d213

@TravisBuddy
Copy link

Hey @Ashley-J-George,
Something went wrong with the build.

TravisCI finished with status errored, which means the build failed because of something unrelated to the tests, such as a problem with a dependency or the build process itself.

View build log

TravisBuddy Request Identifier: 78e4e4e0-f6bd-11ea-afed-a1bc0e34d213

@spamegg1
Copy link
Contributor

spamegg1 commented Sep 14, 2020

@Ashley-J-George

7 E501 line too long (101 > 88 characters)

Run black on your file: https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md
pip install black then black priority_queue.py

@cclauss
Copy link
Member

cclauss commented Sep 14, 2020

Seven lines are longer than 88 characters max.

Removed unwanted white spaces
Kept the max char in a line under 88 char
Added the suggested if condition for underflow
Added the ellipse(...) instead of the entire traceback
@TravisBuddy
Copy link

Hey @Ashley-J-George,
Something went wrong with the build.

TravisCI finished with status errored, which means the build failed because of something unrelated to the tests, such as a problem with a dependency or the build process itself.

View build log

TravisBuddy Request Identifier: 09b750f0-f729-11ea-bb1a-aff04add7ab5

@spamegg1
Copy link
Contributor

2 E501 line too long (90 > 88 characters)
1 W291 trailing whitespace

Can be easily fixed. Run black

else:
return self.queue[2].pop(0)

def print_queue(self):
Copy link
Member

@cclauss cclauss Sep 15, 2020

Choose a reason for hiding this comment

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

Suggested change
def print_queue(self):
def __str__(self) -> str:
return "Your code goes here..."

Instead, please do def __str__(self) -> str: and then we can use str(my_queue) or print(my_queue) to see the results.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How do you do that?

Copy link
Member

@cclauss cclauss Sep 15, 2020

Choose a reason for hiding this comment

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

Replace "Your code goes here..." with a str that you want to see.

Added the proposed changes
@TravisBuddy
Copy link

Hey @Ashley-J-George,
Something went wrong with the build.

TravisCI finished with status errored, which means the build failed because of something unrelated to the tests, such as a problem with a dependency or the build process itself.

View build log

TravisBuddy Request Identifier: 8f540860-f743-11ea-bb1a-aff04add7ab5

@cclauss
Copy link
Member

cclauss commented Sep 15, 2020

207 lines now start with indentation that contains tabs

@Ashley-J-George
Copy link
Contributor Author

207 lines now start with indentation that contains tabs

All indentation are spaces
@TravisBuddy
Copy link

Hey @Ashley-J-George,
Something went wrong with the build.

TravisCI finished with status errored, which means the build failed because of something unrelated to the tests, such as a problem with a dependency or the build process itself.

View build log

TravisBuddy Request Identifier: cdbd5de0-f752-11ea-bb1a-aff04add7ab5

@TravisBuddy
Copy link

Travis tests have failed

Hey @Ashley-J-George,
Please read the following log in order to understand the failure reason.
It'll be awesome if you fix what's wrong and commit the changes.

TravisBuddy Request Identifier: 8c02ee50-f753-11ea-bb1a-aff04add7ab5

@TravisBuddy
Copy link

Travis tests have failed

Hey @Ashley-J-George,
Please read the following log in order to understand the failure reason.
It'll be awesome if you fix what's wrong and commit the changes.

TravisBuddy Request Identifier: 64eddce0-f761-11ea-bb1a-aff04add7ab5

Copy link

@mikelane mikelane left a comment

Choose a reason for hiding this comment

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

I don't think this should be included as an example priority queue data structure.

@Ashley-J-George
Copy link
Contributor Author

I don't think this should be included as an example priority queue data structure.
Tell me the changes that you want me to make and I'll try to incorporate them to my level best

@Ashley-J-George Ashley-J-George deleted the patch-1 branch September 15, 2020 17:48
@cclauss
Copy link
Member

cclauss commented Sep 15, 2020

@Ashley-J-George please reopen this PR so that we can finish it. Despite the other comments, three levels is enough for this demonstration algorithm. Just because Priority queues often times use a heap does not mean that they always use a heap, so your list-based approach was fine. Using dequeue or heapq will hide many of the implementation details that make your simple list-based approach so educational. As we say in our README, we are building algorithms to be educational, to highlight concepts, not to be as fast as the Python standard library.

@Ashley-J-George
Copy link
Contributor Author

Ashley-J-George commented Sep 16, 2020 via email

@cclauss
Copy link
Member

cclauss commented Sep 16, 2020

I am sitting down to go through it but the pull request is closed.

@Ashley-J-George
Copy link
Contributor Author

Ashley-J-George commented Sep 16, 2020 via email

@cclauss
Copy link
Member

cclauss commented Sep 16, 2020

Merged in #2435

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants