Programming Code For Linked List (Addto List)
Programming Code For Linked List (Addto List)
Sub Main()
Call CreateLinkedList() 'call procedure CreateLinedList to create linked list in
memory
Call AddToList("Zebra")
Call AddToList("Ant")
Call AddToList("Elephant")
Call AddToList("Bee")
Call AddToList("Tiger")
Call AddToList("Lion")
Call AddToList("Cheeta")
Call AddToList("Horse")
Console.WriteLine("....................................................................."
)
Console.WriteLine("Print elements in ordered Linked list ")
Console.WriteLine(List(StartPointer).Data)
Console.WriteLine(List(List(StartPointer).Pointer).Data)
Console.WriteLine(List(List(List(StartPointer).Pointer).Pointer).Data)
Console.WriteLine(List(List(List(List(StartPointer).Pointer).Pointer).Pointer).Data)
Console.WriteLine(List(List(List(List(List(StartPointer).Pointer).Pointer).Pointer).Point
er).Data)
Console.WriteLine(List(List(List(List(List(List(StartPointer).Pointer).Pointer).Pointer).
Pointer).Pointer).Data)
Console.WriteLine(List(List(List(List(List(List(List(StartPointer).Pointer).Pointer).Poin
ter).Pointer).Pointer).Pointer).Data)
Console.WriteLine("....................................................................."
)
Console.ReadKey()
End Sub
Sub CreateLinkedList()
Dim Index As Integer
StartPointer = NullPointer '// set start pointer
FreeListPtr = 0 '// set starting position of free list
For Index = 0 To 5 '// link all nodes to make free list
List(Index).Pointer = Index + 1
Next
List(6).Pointer = NullPointer '// last node of free list
End Sub
1
Sub AddToList(ByVal NewItem As String)
If FreeListPtr <> NullPointer Then ''place item at first node of free list if
free space is available
List(FreeListPtr).Data = NewItem
NextFreeNodeAddress = List(FreeListPtr).Pointer
' search data linked list to get position where to place the new item in it
CurrentPointer = StartPointer ' use this pointer variable to go through each
node
End If
FreeListPtr = NextFreeNodeAddress ' set free list pointer to point to new
free node
Console.WriteLine(NewItem & " added to linked list") ' confirm new node added
to linked list
Else
'linked list is full..no more nodes can be added
Console.WriteLine("Sorry..." & NewItem & " can not be added as there is no
free space left in the data linked list")
End If
End Sub
End Module
2
Screen shot