0% found this document useful (0 votes)
11 views3 pages

Linked List Insertion 2

The document is a Visual Basic program that implements a simple linked list structure. It includes functions to display data and insert new data into the list, managing pointers to maintain the list's integrity. The main subroutine initializes the list, displays its contents, attempts to insert new data, and then displays the updated list.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views3 pages

Linked List Insertion 2

The document is a Visual Basic program that implements a simple linked list structure. It includes functions to display data and insert new data into the list, managing pointers to maintain the list's integrity. The main subroutine initializes the list, displays its contents, attempts to insert new data, and then displays the updated list.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Imports System.

Console

Module Module1

Structure Linked

Dim Data As Integer

Dim Pointer As Integer

End Structure

Dim List(6) As Linked

Sub DisplayData(ByRef List, ByVal CurrentPtr)

'Dim CurrentPtr As Integer = StartPtr

While CurrentPtr <> -1

WriteLine(List(CurrentPtr).Data)

CurrentPtr = List(CurrentPtr).Pointer

End While

End Sub

Function InsertData(ByVal List, ByVal CurrentPtr, ByVal FreePtr) As Boolean

Dim NewPtr As Integer

Dim CurrentPtr As Integer = StartPtr

Dim NData As Linked

Write("Enter data:")

Dim InsData As Integer = ReadLine()

If FreePtr = -1 Or FreePtr > 5 Then

Return False

Else

NData.Data = InsData

NData.Pointer = -1

List(FreePtr) = NData
Dim PreviousPtr As Integer = 0

While CurrentPtr <> -1

PreviousPtr = CurrentPtr

CurrentPtr = List(CurrentPtr).pointer

End While

NewPtr = FreePtr

NData.Pointer = NewPtr

List(PreviousPtr) = NData

FreePtr = List(FreePtr).pointer

Return True

End If

End Function

Sub Main()

Dim List(6) As Linked

List(0).Data = 8

List(0).Pointer = 1

List(1).Data = 10

List(1).Pointer = 4

List(2).Data = 17

List(2).Pointer = 6

List(3).Data = 0

List(3).Pointer = 5

List(4).Data = 15

List(4).Pointer = 2

List(5).Data = 0
List(5).Pointer = -1

List(6).Data = 21

List(6).Pointer = -1

Dim StartPtr As Integer = 0

Dim FreePtr As Integer = 3

Call DisplayData(List, StartPtr)

WriteLine()

Dim Result As Boolean = InsertData(List, StartPtr, FreePtr)

If Result = True Then

WriteLine("Data Inserted")

Else

WriteLine("Not inserted")

End If

WriteLine()

Call DisplayData(List, StartPtr)

ReadKey()

End Sub

End Module

You might also like