Skip to content
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

Add a Duplicates Allowed checkbox in Array.py #9

Open
JMCanning78 opened this issue Mar 5, 2019 · 0 comments
Open

Add a Duplicates Allowed checkbox in Array.py #9

JMCanning78 opened this issue Mar 5, 2019 · 0 comments

Comments

@JMCanning78
Copy link
Contributor

JMCanning78 commented Mar 5, 2019

In Lafore's Java applet, there was a radio button to allow or disallow duplicate values in the array. That concept needs to be added in order to show its impact on find and delete operations (and maybe insert as well).
Add a checkbox with the label "Duplicates Allowed" that is initially unchecked and enabled for use. When it is checked, the find function should find all values that match the input search value. Keep the highlight on all matching values after scanning the full array. Similarly, the delete function should delete all matching values. This should be done by changing the algorithm for deleting an item to

  • initialize a shift amount to 0
  • initialize an index pointer to 0
  • while the index pointer is less than the number of elements in the array:
    • compare the item at the index with the value to delete
    • if the values match,
      • remove the current item with an animation
      • increment the shift amount
    • if the values don't match
      • if the shift amount is greater than 0, shift the indexed cell by the shift amount
    • increment the index pointer
  • while the shift amount is greater than 0:
    • decrement the index pointer
    • clear the cell indexed by the pointer (reducing the number of active elements by 1)
    • decrement the shift amount

While it might be wise to include a check for duplicates before inserting a new value when the checkbox is unchecked, don't implement one. There will be some exercises for students to do to see what happens if duplicates are inserted when the data structure is not expecting them.

Place the checkbox in a pane below the 4 other operations (find, insert, delete value, and delete rightmost). It's an option that applies to all the the operations, so it can stay inside the labeled "Operations" box.

Highlighted items that remain after a find operation is completed should be cleared before starting a new find, insert, or delete operations.

@JMCanning78 JMCanning78 changed the title Add a Duplicates Allowed checkbox Add a Duplicates Allowed checkbox in Array.py Mar 5, 2019
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

No branches or pull requests

1 participant