-
Notifications
You must be signed in to change notification settings - Fork 272
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
Use DynamicOneDimensionalArray in ArrayStack #67
Comments
I am willing to work on this issue. Is an Arraystack a static one dimensional array? |
Yes, currently we are using, |
I went through one of the example for dynamic array. It used ctype module and doubled the size of array when it's capacity was full. |
The |
The working of |
I read about amortized cost. We need to use already existing methods of Arraystack in DynamicOneDimensionalArray right? |
You are thinking the opposite of what is required. We need to use the methods of
Similarly the following push ,pydatastructs/pydatastructs/miscellaneous_data_structures/stack.py Lines 104 to 108 in a8e2a96
can be re-written as, def push(self, x):
self.items.append(self.dtype(x)) In fact, the above suggests that once we start using |
There is no need of top because we are appending right? |
Yes, the purpose of
The |
For pop I suggest the following like the example given by you; Current pop function: def pop(self):
if self.top == 0:
raise ValueError("Stack is already empty.")
self.top -= 1
r = self.items[self.top]
self.items[self.top] = None
return r Modified pop function: def pop(self):
self.items.delete(-1) #assuming the delete function displays the item before deleting. |
May be we can use deepcopy to copy the top most element before deleting it. Something like, def pop(self):
top_element = copy.deepcopy(self.items[self._last_pos_filled])
self.items.delete(self._last_pos_filled)
return top_element What do you say? |
Why not a simple copy? Is the item having a subclass(child class objects)? |
We don't know what will be there in the stack. It can be anything. May be an object(in which case
Can you try this out on your system? Does |
Okay, then using deepcopy would be better. You want me to try and check pop with deepcopy right? |
Well, if |
Yes because a simple copy won't clone the values of child objects. |
May be we should try this also: ''' def pop(self): Here there references will be different but values will be same. |
I think it would create shallow copy which will be changed on deletion. |
Description of the problem
Currently we use fixed size arrays in
ArrayStack
which is nothing but wastage of memory. To reduce that problem,DynamicOneDimensionalArray
should be used inside the methods ofArrayStack
.The way of using is left to the one who will fix the issue.
Example of the problem
References/Other comments
The text was updated successfully, but these errors were encountered: