-
Notifications
You must be signed in to change notification settings - Fork 312
Updated __init__.py as for queue requirement #70
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
Closed
Changes from 12 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
2c7cc34
Create
utkarsh0702 4a37e4b
Delete queue.py
utkarsh0702 161ac68
queue.py
utkarsh0702 2442914
Update __init__.py
utkarsh0702 6449369
Update queue.py
utkarsh0702 7c444d2
Updated queue.py file with Dynamic One Dimensional Array
utkarsh0702 18f92e5
Added queue.py
utkarsh0702 928082d
Added Dynamic 1d array queue
utkarsh0702 6e31b53
added dynamic 1d array to queue
utkarsh0702 01d8dc1
Merge branch 'master' into master
utkarsh0702 fa2ee9a
Updated the queue.py acc. to Dynamic 1d
utkarsh0702 8a295ff
Update __init__.py
utkarsh0702 36c10b9
Update __init__.py
utkarsh0702 4682007
Update __init__.py
utkarsh0702 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
from pydatastructs.linear_data_structures import DynamicOneDimensionalArray | ||
|
||
__all__ = [ | ||
'Queue' | ||
] | ||
|
||
_check_type = lambda a, t: isinstance(a, t) | ||
NoneType = type(None) | ||
|
||
class Queue(objects): | ||
def __new__(clas, implementation='array', **kwargs): | ||
if implementation == 'array': | ||
return ArrayQueue( | ||
kwargs.get('item', None), | ||
kwargs.get('dtype', int)) | ||
raise NotImplementedError("%s hasn't been implemented yet."%(implementation)) | ||
|
||
def append(self, *args, **kwargs): | ||
raise NotImplementedError("This is an abstract method.") | ||
|
||
def popleft(self, **kwargs): | ||
raise NotImplementedError("This is an abstract method.") | ||
|
||
def __len__(self, **kwargs): | ||
raise NotImplementedError("This is an abstract method.") | ||
|
||
|
||
class ArrayQueue(Queue): | ||
__slots__ = ['item','dtype'] | ||
front= -1 | ||
count= 0 | ||
def __new__(clas, item = None, dtype = int): | ||
if item is None: | ||
item= DynamicOneDimensionalArray(dtype, 0) | ||
else: | ||
item= DynamicOneDimensionalArray(dtype, item) | ||
|
||
obj = object.__new__(clas) | ||
obj.item, obj.dtype = item, items._dtype | ||
return obj | ||
|
||
def append(self, x): | ||
if self.front == -1: | ||
self.front=0 | ||
self.item.append(x) | ||
self.count+=1 | ||
|
||
def popleft(self): | ||
if (self.front == -1): | ||
raise ValueError("Queue is empty.") | ||
r = dc(self.item[self.front]) | ||
self.item.delete(self.front) | ||
self.front += 1 | ||
return r | ||
|
||
def __len__(self): | ||
if (self.front == -1): | ||
return 0 | ||
else: | ||
return (self.count- self.front) | ||
|
||
def __str__(self): | ||
""" | ||
Used for printing. | ||
""" | ||
return str(self.item._data) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.