473,324 Members | 2,248 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

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

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
1 1439
Killer42
8,435 Expert 8TB
Have you tested the code?
Oct 17 '07 #2

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

Similar topics

8
by: J Peterman | last post by:
Im having a nightmare trying to understand these nodes and linked lists. I've posted my code for my node.h, node.cpp, linkedlist.h and linkedlist.cpp files in separates replies. Can someone...
10
by: cody | last post by:
Why isn't there a LinkedList in .NET? Was the reason that the mark&sweep GC algorithm has problems with heavily linked data? A LinkedList is very important is you have huge lists and append a...
10
by: LP | last post by:
Hi, I was asked at the tech screening what the linked list was which I answered with "academic" definition. Then a guy asked me how I would implement a linked list in C# and what would be a good...
2
by: Justin Crites | last post by:
I have an object which I want to be serializable. I have marked with with . The object only has a single data member, which is a LinkedList<int>. This linked list is a private member and cannot...
20
by: martin-g | last post by:
Hi. Mostly I program in C++, and I'm not fluent in C# and .NET. In my last project I began to use LinkedList<and suddenly noticed that can't find a way to sort it. Does it mean I must implement...
6
by: Phillip.Ross.Taylor | last post by:
When I designed my application I created an object called "Orderable" which exposes a public property "sequence". Then a few objects inherit from this. I'll just call them ObjectX for the sake...
3
by: huiling25 | last post by:
I don't know why the customer records cannot be inserted into the linked list and the head of the linked list keep pointing to null... //ListNode.java public class ListNode{ private Object...
1
by: sejong510 | last post by:
MSDN has an example of creating a LinkedList populated with String objects: http://msdn2.microsoft.com/en-us/library/he2s3bh7.aspx But, how would you have a LinkedList of a created class?...
1
by: CaseySimplified | last post by:
I am writing a LinkedList class from scratch without using the already defined LinkedList class. The only thing that doesn't seem to be working is adding removing and getting the last link in the...
5
by: Alberto Bencivenni | last post by:
Hi All, Is there a reason why it is not possible to serialize a geenric LinkedList<Tobject containing a custom class marke serializable? Thanks, Alberto
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.