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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

My name is MudSystems 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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Pascal

From novice to tech pro — start learning today.