472,958 Members | 1,738 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

What data type would you prefer and why?

I wanted to practice some Linked List stuff, so I set out to create a
linked list. The plan was to create the following:

(1) A linked list class in Visual Basic
(2) A non-class based linked list using functions in C
(3) A linked list class in C++

I started with Visual Basic and I wrote an IList interface that I
wanted my list to implement. When I had started, somehow I thought
this time, I'd first use a collection as the ingredient, and so it
would not really be a linked list. It would be an extended collection
behaving like a (not linked, but just a) list, as in list of things.
And my new agenda would then be,

(1) A list (not a linked list) class in Visual Basic by extending the
Collection object.
(2) A linked list class in Visual Basic
(3) A linked list in Visual Basic that is not class-based but has a
struct (Type) and global functions in a standard module (.bas).
(4) A non-class based linked list using functions in C
(5) A linked list class in C++

I don't like to create lists if they have no meaning, so I thought it
would be a good idea if the list was a list of something and not just
"ints". So, I made a list of my friends on the Joel On Software forum.
I called the list MyFriends.

I have just finished implementing a list by extending the Visual
Basic's Collection object. My list has the following interface:

Expand|Select|Wrap|Line Numbers
  1. Public Function AddAtPos(ByRef Object As Object, _
  2. ByVal Index As Long) As Boolean
  3. End Function
  4.  
  5. Public Function PeekAtPos(ByVal Index As Long) As Object
  6. End Function
  7.  
  8. Public Function RemoveAtPos(ByVal Index As Long) As Boolean
  9. End Function
  10.  
  11. Public Property Get Count() As Long
  12. End Property
  13.  
  14. Public Function Contains(Object As Object) As Boolean
  15. End Function
  16.  
  17. Public Function IndexOf(Object As Object) As Long
  18. End Function
  19.  
  20. Public Sub Serialize()
  21. End Sub
  22.  
  23. Public Sub Deserialize()
  24. End Sub
  25.  
  26. Public Sub Clear()
  27. End Sub
  28.  
  29. Public Sub Sort(ByVal SortOrder As SortOrders)
  30. End Sub
  31.  
  32. Public Sub Reverse()
  33. End Sub
  34.  
If you're interested, you can find the source code and the executable
for my first experiment here.

http://www.vbforums.com/showthread.p...hreadid=303400

Now, I am set to implement item number (2) in my agenda - the linked
list class in Visual Basic. Once again, the semantics remain the same.
I intend to keep the list as a list of friends. So each node in the
list is a friend. While designing the "node" class or the "MyFriend"
class, I stumbled accross this problem. I am recording two pieces of
information about each friend:

(1) Name
(2) Phone Number

Both are of String type. The problem was not with these, but with the
"node pointer" item. I have three data types in mind that I can use to
point to the next node. I am confused as to which one would be a good
choice, and I want your opinion on the same.

Here's what I have thought the node/MyFriend class as:

Expand|Select|Wrap|Line Numbers
  1. Implements IList
  2.  
  3. Private mName As String
  4. Private mPhoneNumber As String
  5.  
  6. '===Which one do I choose?=======
  7. 'Private mNextFriend As MyFriend
  8. '         OR
  9. 'Private mNextFriend As Long
  10. '         OR
  11. 'Private mNextFriend() As Byte
  12. '==================================
  13.  
Let me argue each case, as I thought about them. Starting with the
last, if I take the mNextFriend field as a Byte array, it would help
me....do nothing, basically. So, ruled out.

Next, if took the mNextFriend field as a Long, I think it would be the
ideal thing to do, because VB6 Long's are indeed 32-bit values, and
then I would use the mNextFriend Long field to point to a new instance
of MyFriend type, using the ObjPtr function. I would dereference the
mNextFriend Long type by using RtlMoveMemory. That sounds like a nice
plan. However, the problem with this is that it does not strictly
confirm to a Linked List set up, because of the generic nature of this
Long pointer. This pointer could be used to point not only to MyFriend
types but to anything. Since I am going to be the developer audience
for this class, and hence this is only dogfood, it is no problem, but
in general, I don't like it as a habit and I always want my code to
represent what it ought to represent. So, this would be like
compromising on a trivial issue.

If I use mNextFriend as a MyFriend type, I solve the problem of the
generic pointer by restricting it to the MyFriend type. So, it's more
disciplined this way, but now, the field is not really a pointer. It
is an object. Of course, it is still a 32-bit reference to the actual
object, but it is still not a real pointer.

So, I am confused. If you were to be doing this, what option would you
choose and why? To me, the Long seems like ok, although it is a little
bit of a compromise on the type-checking.
Nov 14 '05 #1
3 2028

"Sathyaish" <Vi****************@yahoo.com> wrote

If I use mNextFriend as a MyFriend type, I solve the problem of the
generic pointer by restricting it to the MyFriend type. So, it's more
disciplined this way, but now, the field is not really a pointer. It
is an object. Of course, it is still a 32-bit reference to the actual
object, but it is still not a real pointer.


IMHO, the field is a type safe pointer, and I would have thought

Private mNextFriend As IList

would have been the obvious choice for the task. That would
have restricted those fields to objects that implement the IList
interface, no matter what type of object they actually were....

LFS
Nov 14 '05 #2
Sathyaish wrote:
I wanted to practice some Linked List stuff, so I set out to create a
linked list. The plan was to create the following:


No real advice here except.... check out these samples.... they may give
you some ideas (plus they're great samples)

DataBagLib and LinkedListLib
http://killervb.com/Libraries.aspx

--
Ken Halter - MS-MVP-VB - http://www.vbsight.com
Please keep all discussions in the groups..
Nov 14 '05 #3
Sathyaish wrote:

I wanted to practice some Linked List stuff, so I set out to create a
linked list. The plan was to create the following:

(1) A linked list class in Visual Basic
(2) A non-class based linked list using functions in C
(3) A linked list class in C++


This VB and C++ junk is foully off-topic here in c.l.c. F'ups
set. See the links in my sig below for help. Singly linked lists
are extremely simple. For an example in C see the freverse.c
example contained in:

<http://cbfalconer.home.att.net/download/ggets.zip>

--
Some useful references:
<http://www.ungerhu.com/jxh/clc.welcome.txt>
<http://www.eskimo.com/~scs/C-faq/top.html>
<http://benpfaff.org/writings/clc/off-topic.html>
<http://anubis.dkuug.dk/jtc1/sc22/wg14/www/docs/n869/> (C99)
<http://www.dinkumware.com/refxc.html> C-library
Nov 14 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

220
by: Brandon J. Van Every | last post by:
What's better about Ruby than Python? I'm sure there's something. What is it? This is not a troll. I'm language shopping and I want people's answers. I don't know beans about Ruby or have...
28
by: David MacQuigg | last post by:
I'm concerned that with all the focus on obj$func binding, &closures, and other not-so-pretty details of Prothon, that we are missing what is really good - the simplification of classes. There are...
92
by: Reed L. O'Brien | last post by:
I see rotor was removed for 2.4 and the docs say use an AES module provided separately... Is there a standard module that works alike or an AES module that works alike but with better encryption?...
11
by: modemer | last post by:
If I define the following codes: void f(const MyClass & in) {cout << "f(const)\n";} void f(MyClass in) {cout<<"f()\n";} MyClass myclass; f(myclass); Compiler complain that it can't find...
121
by: typingcat | last post by:
First of all, I'm an Asian and I need to input Japanese, Korean and so on. I've tried many PHP IDEs today, but almost non of them supported Unicode (UTF-8) file. I've found that the only Unicode...
3
by: Andrew Mueller | last post by:
Hello, I tried this question prior and got no response, so thought I would try to explain differently.. I am not sure which type of object to pass between a VB 6.0 ActiveX dll and C#. I am...
13
by: Jason Huang | last post by:
Hi, Would someone explain the following coding more detail for me? What's the ( ) for? CurrentText = (TextBox)e.Item.Cells.Controls; Thanks. Jason
12
by: Robert.Holic | last post by:
Hi All (first time caller, long time listener), I've stumbled across a problem that I have yet to figure out, although Im sure I'll kick myself when I figure it out. Here it is: I need to...
5
by: rockdale | last post by:
Hi, all: I have a website with its own login page. Now one of my clients want their employees log into my website from their website. They want to have their login page (look and feel are...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
2
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.