Guest User

Untitled

a guest
Apr 22nd, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. public boolean remove(Object item)
  2. {
  3. int index, origIndex;
  4. //compute the hash index of item for a table of size n
  5. index = (item.hashCode()& Integer.MAX_VALUE)%table.length;
  6. //save the original hash index
  7. origIndex = index;
  8. // compute the hash table index
  9. index = (item.hashCode() & Integer.MAX_VALUE) % table.length;
  10.  
  11. // scan the array and return true if item is in list
  12. while (index != origIndex)
  13. {
  14. if(table[index] == null ||
  15. table[index].deletedData == false && table[index].available == true)
  16. return false;
  17.  
  18. if (table[index].data.equals(item) && table[index].deletedData == false)
  19. {
  20. table[index].data = -2;
  21. table[index].deletedData = true;
  22. table[index].available = true;
  23.  
  24. // decrement hash table size and return true
  25. hashtableSize--;
  26. return true;
  27. }
  28.  
  29. index = (index+1)%table.length;
  30. }
  31.  
  32. return false;
  33. }
Add Comment
Please, Sign In to add comment