|
-
Apr 30th, 2000, 04:02 AM
#1
Thread Starter
PowerPoster
Hi there
Is it possible to make linked lists in VB? I'd need them for my script system so if anyone knows please tell me
-
Apr 30th, 2000, 04:53 AM
#2
Hyperactive Member
What exactly do you mean?
I'm not sure what you mean by a linked list, but do you mean two listboxes that have the same data? or perhaps they have different data that are related to each other? I've done both if that's what you're asking about. Could you be a little more specific in what you need?
bob
-
Apr 30th, 2000, 04:57 AM
#3
The only way you can implement a linked list ADT is using the built in array.
And it would probably go something like this:
Type someType
s as string
link as integer
end type
class someClass
private const UPPER_BOUND=100
private node(100) as someType
private used(100) as someType
private head as integer
private cur as integer
private temp as integer
private ins as integer
public sub New() 'arbitrary constructor
dim i as integer
head=ins=cur=temp=-1
for i=lbound(used) to ubound(used)
used(i)=0
end sub
sub insert(someType record)
temp=cur
ins=getNew()
if ins<0 then
msgbox"Note enough memory allocated"
exit sub
end if
node(ins).s=record.s
node(ins).link=-1
used(ins)=1
if head < 0 then
head=ins
exit sub
end if
if node(head).s > record.s then
node(ins).link=head
head=ins
exit sub
end if
cur=head
while node(cur).link <> -1
if(node(node(cur).link).s > record.s then
exit do // or something like that
end if
cur=node(cur).link
wend
node(ins).link=node(cur).link
node(cur).link=ins
cur=temp
end sub
sub delete(someType record)
dim a as string
a=record.s
if head=-1 then
exit sub
end if
if node(head).s=a then
used(head)=0
head=node(head).link
else
cur=head
while node(cur).link <> -1
if node(node(cur).link).s = a then
exit do // or something like that
end if
cur=node(cur).link
wend
used(node(cur).link)=0
node(cur).link=node(node(cur).link).link
end if
end sub
function getNew()
for i=0 to i < UPPER_BOUND
if used(i)=0 then
getNew=i
end if
next i
getNew=-1
end function
This is a basic implementation of the singly linked list using the build in array and it may not work the way it is right now because i just typed it from the top of my head.
I hope you get the idea though.
good luck
KO
-
Apr 30th, 2000, 09:45 AM
#4
Hyperactive Member
Isnt it relativley easy to implement a linked list using class modules? Or am I way of the mark?
eg:
If you had a class module called myClass you could just create an instance of myClass inside it?
"People who think they know everything are a great annoyance to those of us who do."
-
Apr 30th, 2000, 11:59 AM
#5
Fanatic Member
I know of two ways to impliment linked lists in VB.
One involves creating a new "List item" object and they hold pointers (references) to the next (and previous in a double) item in the list.
The other way is with an array of types where one type hold the data, the other holds the array position of the next item.
The second one seems to be a bit quicker but you need to spend some time writing sort,search,next,prev,eof functions.
probably worth writing a dll to hold it all in then declare a new list when you need it. they all your properties are there for you
Paul Dwyer 
Network Engineer
Aussie In Tokyo
Using Powerbasic 6 & VB6 SP4 (Please also add your VB Version to your signature!)
-
Apr 30th, 2000, 12:00 PM
#6
Thread Starter
PowerPoster
First, tanks both for the answers!
Noone, you're a genius I never tried to use classes (took Types) so I tried it and IT WORKS Thanks alot!
-
Apr 30th, 2000, 12:02 PM
#7
Thread Starter
PowerPoster
Oh, just after repling comes a new answer Thanks to you too Paul, that's what I did before, with Types... well, the classes work fine but thx anyway.
-
May 1st, 2000, 04:42 AM
#8
Hyperactive Member
Glad to be of assistance Fox. Just out of curiousity what exactly are you trying to use this for? I hate to admit it but using classes is usually slower then using an UDT . Just that coming from a Java background I'm used to thinking with classes, there are no UDT's in Java.
"People who think they know everything are a great annoyance to those of us who do."
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|