sam davis text --> string manipulation... (1 Viewer)

saladsurgery

kicking the cack
Joined
Jul 26, 2002
Messages
943
Location
over there
Gender
Male
HSC
2002
something is freakin me out in the string manipulation section of sam davis's SDD text:

p 135, the second delete algo for strings

BEGIN Delete (Start,Finish,DeleteString)

Temp = DeleteString
Position = Start
Length = Finish - Start + 1

WHILE Position <= Finish
Temp(Position) = Temp (Position + Length)
Add 1 to Position
ENDWHILE

Reduce size of Temp by Length
Delete = Temp

END Delete


Can someone check this? I'm not sure, but...

If you delete part of a string that is shorter than the remaining part, then you get some sort of crazy duplication thing going on.

eg:

to delete "pha" from elephantitis"

  1. "p" is replaced with "n" --> elenhantitis
  2. "h" is replaced with "t" --> elentantitis
  3. "a" is replaced with "i" --> elentintitis
  4. since Position is now > Finish, the loop exits and "tis" is cut off, so you get "elentinti" instead of "elentitis".
    [/list=1]
    confused... :confused:

    ---edit---
    sam, i have seen you floating around these boards... any comments?
 
Last edited:

Lazarus

Retired
Joined
Jul 6, 2002
Messages
5,965
Location
CBD
Gender
Male
HSC
2001
Mmm your analysis does appear to be correct. I don't have the textbook - what does it say the algorithm is meant to do?
 

SamD

Member
Joined
Jul 21, 2002
Messages
256
Gender
Male
HSC
N/A
Yep, you're quite right it is an error. What's strange is that you're the first one to find it, well done! I guess I'm not perfect after all.

Here's a corrected version:

BEGIN Delete (Start,Finish,DeleteString)

Temp = DeleteString
Position = Start
Length = Finish - Start + 1
DelLength = Length of DeleteString - Length

WHILE Position <= DelLength
Temp(Position) = Temp (Position + Length)
Add 1 to Position
ENDWHILE

Reduce size of Temp by Length
Delete = Temp

END Delete

We'll fix it in the next reprint.

Sam
 

saladsurgery

kicking the cack
Joined
Jul 26, 2002
Messages
943
Location
over there
Gender
Male
HSC
2002
Originally posted by SamD
Yep, you're quite right it is an error. What's strange is that you're the first one to find it, well done! I guess I'm not perfect after all.
it was actually a mate of mine who picked it, cramming the weekend before the software trial... neither of us were too sure about what was going on there, but the new one makes sense from here :)
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Top