Discussion:
search function
(too old to reply)
kun qian
2011-11-12 23:02:00 UTC
Permalink
In the description search is said to return a boolean. But in delete
search is suppose to return the position. I am confused about the
design. could someone explain what's going on?
Kérberos Caelestius
2011-11-13 00:25:34 UTC
Permalink
Post by kun qian
In the description search is said to return a boolean. But in delete
search is suppose to return the position. I am confused about the
design. could someone explain what's going on?
I found it convenient to create a private "_search" method, which
takes as parameters k (by value), slotIndex and cellIndex (by
reference), has return value bool (i.e. the success flag) and (if
successful) modifies slotIndex and cellIndex to contain the desired
information.

kérberos
kun qian
2011-11-13 01:23:43 UTC
Permalink
On Nov 12, 7:25 pm, Kérberos Caelestius
Post by Kérberos Caelestius
Post by kun qian
In the description search is said to return a boolean. But in delete
search is suppose to return the position. I am confused about the
design. could someone explain what's going on?
I found it convenient to create a private "_search" method, which
takes as parameters k (by value), slotIndex and cellIndex (by
reference), has return value bool (i.e. the success flag) and (if
successful) modifies slotIndex and cellIndex to contain the desired
information.
kérberos
Why not just reimplement search inside of delete, that my best guess.
Kérberos Caelestius
2011-11-13 01:49:34 UTC
Permalink
Post by kun qian
On Nov 12, 7:25 pm, Kérberos Caelestius
Post by Kérberos Caelestius
Post by kun qian
In the description search is said to return a boolean. But in delete
search is suppose to return the position. I am confused about the
design. could someone explain what's going on?
I found it convenient to create a private "_search" method, which
takes as parameters k (by value), slotIndex and cellIndex (by
reference), has return value bool (i.e. the success flag) and (if
successful) modifies slotIndex and cellIndex to contain the desired
information.
kérberos
Why not just reimplement search inside of delete, that my best guess.
Why not avoid writing the same algorithm in 2 different places? ...
cs240
2011-11-13 04:26:40 UTC
Permalink
Either one of these two approaches would work for the purpose of this
assignment. However, it's always good to eliminate duplicate code,
therefore I would say using a separate helper method is probably better.


Vivian
CS240 Tutor
Post by Kérberos Caelestius
On Nov 12, 7:25 pm, K?rberos Caelestius
Post by Kérberos Caelestius
Post by kun qian
In the description search is said to return a boolean. But in delete
search is suppose to return the position. I am confused about the
design. could someone explain what's going on?
I found it convenient to create a private "_search" method, which
takes as parameters k (by value), slotIndex and cellIndex (by
reference), has return value bool (i.e. the success flag) and (if
successful) modifies slotIndex and cellIndex to contain the desired
information.
k?rberos
Why not just reimplement search inside of delete, that my best guess.
Why not avoid writing the same algorithm in 2 different places? ...
Loading...