Linked List implementation in Visual Basic

Category:

Lists, Collections and Arrays

Type:

Snippets

Difficulty:

Intermediate

Author:
Anonymous

Version Compatibility: Visual Basic 6, Visual Basic 5

More information:
Since Linked list implementation requires pointer and unfortunately VB don't have any. I implement it by making a data type that has element and "Pointer".this so-called "pointer" acts like a pointer but naturally it is more of an Index. [element|n = 0 ] --> [element|n+1]-->[element|n+2] --> and so on... ( --- feel free to give ur corrections or suggestions --- )

Instructions: Copy the declarations and code below and paste directly into your VB project.

Declarations:

Option Explicit

 

Private Type LinkedlistNode

 

 element As Integer

 pointer As Integer

 

End Type

 

Dim length As Integer

Dim node As LinkedlistNode

 

 

 

Code:

 

Function createList(size As Integer)

'creates a List A ;syntax -- A = createList(10)

 length = size

 i% = 0

 

  For i = 0 To i = size

  

      node.element = 0

      node.pointer = i

      i = i + 1

      

  Next

     

End Function

 

Function setElement(val As Integer, pos As Integer)

'place an element= val to the position = pos

 If (pos > 1) Then

 

   i% = 0

     

   Do Until i = pos

   

       node.pointer = i

 

   Loop

     

       node.element = val

       node.pointer = i

     

     Else

    

        node.element = val

        node.pointer = 0

      

  End If

  

 length = length + 1

  

End Function

 

Function getElement(pos As Integer) As Integer

'returns the element at the position = pos

 If (pos <= length) Then

   

    For i% = 0 To i = pos

    

경축! 아무것도 안하여 에스천사게임즈가 새로운 모습으로 재오픈 하였습니다.
어린이용이며, 설치가 필요없는 브라우저 게임입니다.
https://s1004games.com

      node.pointer = i

      i = i + 1

      

    Next

    

      node.pointer = i

      getElement() = node.element

      

   Else

   

     Err.Raise

     

 

End Function

 

Function setLength(newSize As Integer)

'sets a new size to the List

 If (newSize > length) Then

 

   diff% = newSize - length

   

    For i% = 1 To i = diff

    

      addLast (0)

      i = i + 1

      

    Next

  

  Else

  

    diff = length - newSize

    

    i = 0

    

    Do Until i = newSize

    

      node.pointer = i

      

    Loop

         

      For i = size + 1 To i = length

     

         node.element = Nothing

         node.pointer = Nothing

            

         i = i + 1

         

      Next

      

  End If

  

 length = newSize

         

End Function

 

Private Function addLast(val As Integer)

 

 addlen% = length + 1

 

  node.element = 0

  node.pointer = addlen

  

End Function

 

 

 

[출처] http://www.freevbcode.com/ShowCode.asp?ID=8745

 

 

본 웹사이트는 광고를 포함하고 있습니다.
광고 클릭에서 발생하는 수익금은 모두 웹사이트 서버의 유지 및 관리, 그리고 기술 콘텐츠 향상을 위해 쓰여집니다.
번호 제목 글쓴이 날짜 조회 수
918 1932 > DP > #37 정수 삼각형 졸리운_곰 2020.04.12 74
917 Programmers > 2018 서머코딩 > #36 예산 졸리운_곰 2020.04.12 65
916 9084 > DP> #35 동전 졸리운_곰 2020.04.07 101
915 BaekJoon _ 백준 1149 > DP> #34 RGB 거리 졸리운_곰 2020.04.02 91
914 BaekJoon _ 백준 1026 > 탐색> #33 보물 졸리운_곰 2020.04.02 89
913 Programmers > 연습문제 > #32 N-Queen 졸리운_곰 2020.04.01 60
912 Programmers > 연습문제 > #31 2 x n 타일링 졸리운_곰 2020.04.01 68
911 List of freely available programming books 졸리운_곰 2020.03.31 183
910 How to do pointers in Visual Basic file 졸리운_곰 2020.03.26 74
» Linked List implementation in Visual Basic 졸리운_곰 2020.03.24 50
908 Programmers > 스택/큐(Stack/Queue) > #30 기능개발 졸리운_곰 2020.03.23 64
907 Programmers > #28 winter recruit > #2 [JAVA] 졸리운_곰 2020.03.23 46
906 Programmers > 깊이/너비 우선 탐색(DFS/BFS) > #27 타겟 넘버 [JAVA] 졸리운_곰 2020.03.09 65
905 Programmers > 완전탐색 > #26 소수찾기(level 2) [JAVA] 졸리운_곰 2020.03.09 68
904 Programmers > #25 winter recruit > #1 [JAVA] 졸리운_곰 2020.03.08 46
903 Programmers > Level 1 > #24 소수찾기 [Python] 졸리운_곰 2020.03.08 65
902 Programmes > #23 문자열 내 마음대로 정렬하기 [Python] 졸리운_곰 2020.03.08 61
901 Programmers > Hash > #22 위장 [JAVA] 졸리운_곰 2020.03.07 54
900 Programmers > Sort > #21 H-Index [JAVA] 졸리운_곰 2020.03.07 60
899 [Programmers] #20 라면공장 [JAVA] 졸리운_곰 2020.03.06 83
대표 김성준 주소 : 경기 용인 분당수지 U타워 등록번호 : 142-07-27414
통신판매업 신고 : 제2012-용인수지-0185호 출판업 신고 : 수지구청 제 123호 개인정보보호최고책임자 : 김성준 sjkim70@stechstar.com
대표전화 : 010-4589-2193 [fax] 02-6280-1294 COPYRIGHT(C) stechstar.com ALL RIGHTS RESERVED