Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Inserting into a doubly linked list

Status
Not open for further replies.

thumper808

Technical User
Apr 22, 2001
26
CA
Hi everyone,
I have a problem with how to insert a node into the middle of a doubly linked list. I have a project which takes in a student record from a DAT file and displays it in a form in VB. I don't know how to code the cmdInsert_click() on the form or the actual Insert function in my List class. My VB project so far can be downloaded from my friend's site here
just right click and select 'save target as' on each one you want to see.

I think it's like the delete function but I can't get my head around this...

Any help would be greatly appreciated. Thank you so much. You guys are awesome...you've helped me out a ton of times before.

Shane.
 
' heres a first guess, sorry i didn't have time to test.
' i think you should get the general jist from this anyway
' (list.cls)

Public Function Insert(ByRef NewData As Object, ByVal InsertionPoint As Object) As Object
Dim oTemp As Node

' assuming NewData has been allocated

' find insertionpoint in list
Set oTemp = m_First
While Not oTemp Is InsertionPoint And Not oTemp Is Nothing
Set oTemp = oTemp.NextNode
Wend

If Not oTemp Is Nothing Then
' found the node we are inserting after
If oTemp.NextNode Is Nothing Then ' cannot 'insert' at end of list so add the node
Add NewData
Else
Set NewData.NextNode = oTemp.NextNode
Set oTemp.NextNode.PreviousNode = NewData
Set oTemp.NextNode = NewData
Set NewData.PreviousNode = oTemp
End If
Else
' error insertion point not in list
End If
End Function
 
Thank you very much RichardF! I got the jist of it and it helps me immensely. However, when I'm trying to test it in the form...I don't know how to get all the new information entered to point to a student... Could you please help me with the form part? I have a feeling it would all come together... I've tried alot of things to make it happen but unfortunately, doubly linked lists are not my strong suit. Thanks again.

Shane.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top