By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,457 Members | 1,298 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,457 IT Pros & Developers. It's quick & easy.

can anyone check my linkedlist implementation in VB6 if its okay..thanks!

P: 43
' i made a type that has Element and Pointer, but this so called pointer acts like
'an index , in order to linked to the next node pointer will just increment.

Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2.  
  3. Private Type LinkedlistNode
  4.  
  5.  element As Integer
  6.  pointer As Integer
  7.  
  8. End Type
  9.  
  10. Dim length As Integer
  11. Dim node As LinkedlistNode
  12.  
  13. Function createList(size As Integer)
  14.  
  15.  length = size
  16.  i% = 0
  17.  
  18.   For i = 0 To i = size
  19.  
  20.       node.element = 0
  21.       node.pointer = i
  22.       i = i + 1
  23.  
  24.   Next
  25.  
  26. End Function
  27.  
  28. Function setElement(val As Integer, pos As Integer)
  29.  
  30.  If (pos > 1) Then
  31.  
  32.    i% = 0
  33.  
  34.    Do Until i = pos
  35.  
  36.        node.pointer = i
  37.  
  38.    Loop
  39.  
  40.        node.element = val
  41.        node.pointer = i
  42.  
  43.      Else
  44.  
  45.         node.element = val
  46.         node.pointer = 0
  47.  
  48.   End If
  49.  
  50.  length = length + 1
  51.  
  52. End Function
  53.  
  54. Function getElement(pos As Integer) As Integer
  55.  
  56.  If (pos <= length) Then
  57.  
  58.     For i% = 0 To i = pos
  59.  
  60.       node.pointer = i
  61.       i = i + 1
  62.  
  63.     Next
  64.  
  65.       node.pointer = i
  66.       getElement() = node.element
  67.  
  68.    Else
  69.  
  70.      Err.Raise
  71.  
  72.  
  73. End Function
  74.  
  75. Function setLength(newSize As Integer)
  76.  
  77.  If (newSize > length) Then
  78.  
  79.    diff% = newSize - length
  80.  
  81.     For i% = 1 To i = diff
  82.  
  83.       addLast (0)
  84.       i = i + 1
  85.  
  86.     Next
  87.  
  88.   Else
  89.  
  90.     diff = length - newSize
  91.  
  92.     i = 0
  93.  
  94.     Do Until i = newSize
  95.  
  96.       node.pointer = i
  97.  
  98.     Loop
  99.  
  100.       For i = size + 1 To i = length
  101.  
  102.          node.element = Nothing
  103.          node.pointer = Nothing
  104.  
  105.          i = i + 1
  106.  
  107.       Next
  108.  
  109.   End If
  110.  
  111.  length = newSize
  112.  
  113. End Function
  114.  
  115. Private Function addLast(val As Integer)
  116.  
  117.  addlen% = length + 1
  118.  
  119.   node.element = 0
  120.   node.pointer = addlen
  121.  
  122. End Function
Oct 17 '07 #1
Share this Question
Share on Google+
1 Reply


Expert 5K+
P: 8,434
Have you tested the code?
Oct 17 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.