Delete using pointers

Hi I'm running Code Warrior,

I've got a linked list set up using pointers. Can anyone give me the code for deleting an item from the list? I found an algorithm in a book but I'm all confused about the variables etc. Please include the variable decleration and try using normal variable names so I know what youre talking about.
Thanks a bunch!
LVL 1
yaelieAsked:
Who is Participating?
 
My name is MudConnect With a Mentor Systems EngineerCommented:
The principle thing to do is...


this is the link (Double link)...

  Item1 <-> Item2 <-> Item3 <-> ItemN

the way to delete an item, let say Item2, will be, to assign the pointer value of the previuos pointer of Item2 to Item3, and the Next pointer value, to Item1, and do a FreeMem(Item2, SizeOf(Item2)) or Dispose(Item2) depending on what procedure you used to create the link...


Let see you have this...

Type
  PointerToList = ^List;
  List = Record
    Value: Integer;
    PrevItem: PointerToList;
    NextItem: PointerToList;
  End;
Var
  Start,Previous,Current,Finish: PointerToList;

Procedure DeleteItem(WhatToDelete: PointerToList);
Var
  PrevT,NextT: PointerToList;
Begin
  PrevT:=WhatToDelete^.PrevItem;
  NextT:=WhatToDelete^.NextItem;
  Dispose(WhatToDelete); (*Or FreeMem(WhatToDelete,SizeOf(WhatToDelete))*)
  PrevT^.NextItem:=NextT;
  NextT^.PrevItem:=PrevT
End;
0
 
yaelieAuthor Commented:
great, and thanx for the quick response. I cannot try this from the computer I'm using right now, I'll try it first thing tomorrow morning and get back to you k?

thank you!!!
0
 
yaelieAuthor Commented:
whatboy,

I tried doing what you gave me but its not really working. Its basicly choking on the PrevT and the NextT giving me type mismatches.

any idea what i can do?

thanxx..

0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
yaelieAuthor Commented:
Also, i forgot to state that I'm dealing with records not single items (ie i'm setting up records with several items in them and want to delete an entire record)
0
 
My name is MudSystems EngineerCommented:
Place the code of the "Type Structure" you're using for the link...
0
 
My name is MudSystems EngineerCommented:
So:...

>>Also, i forgot to state that I'm dealing with records not single items...

Is the same, girl [you are a girl, right???] in fact when creating a link you create it like a sequence of the structure you have [Records] and assign some memory using a pointer, and you delete them by dealocating that memory that the pointer is "pointing" [sorry]...
0
 
My name is MudSystems EngineerCommented:
HELLOOOOoooo... HELLOoooo... HELLooooo... HELloooo... HElloooo... Hellooooo... helloooo... ???
0
 
My name is MudSystems EngineerCommented:
Telephone Line

                                       Hello - how are you
                                       Have you been alright, through all those lonely nights,
                                       That's what I'd say, I'd tell you everything,
                                       If you'd pick up that telephone.

                                       Hey - how you feelin'
                                       Are you still the same
                                       Don't you realize the things we did were all for real not a dream,
                                       I just can't believe
                                       They've all faded out of view.

                                       I look into the sky
                                       And I wonder why

                                       Chorus

                                       Telephone line, give me some time, I'm living in twilight
                                       Telephone line, give me some time, I'm living in twilight

                                       O.K. so no - one's answering,
                                       Well can't you just let it ring a little longer
                                       I'll just sit tight, through shadows of the night
                                       Let it ring for evermore.

                                       Chorus - repeat
0
 
yaelieAuthor Commented:
sorry for the delay..
0
All Courses

From novice to tech pro — start learning today.