• Re: Linked Lists

    There does not appear to be an easy way to include parameters when creating an object

    I discovered during some reading that you can use something called a Factory pattern to do this

    Instead of

    set c = new cNode(somestring,someobject) the factory pattern to me at least suggest taking this approach
    set c = somefunctionname(somestring,someobject)

    In that same project, have a module that includes the public fuction. The job of this function is to do all the steps of setting the object as new and initializing the property values.

    Function CreatecNode(byval somestring as String, byref someobject as cNode) as cnode

  • Re: Linked Lists

    Yeah I think that being able to set initial values like that is a part of the polymorphism of oop.

    In other languages like c++ you can create multiple initializing routines with passed parameters which you specify when you create the new object.

  • Re: Linked Lists

    I just saw it mentioned on some page but am not sure if I am using the concept correctly. I think I created my first linked list based on the image below if I formatted correctly. If not, the list is a node with the value of A with a next pointing to the node on the right and so on. Once the list is created it sets it to the variable sList.


    I notice that my image is again way too small. Any idea why that is happening?

    Subroutine -

    Class - cNode

    Class - cFactory

    Again I dont know if this follows factory pattern correctly or if it is even useful here or not.

  • Re: Linked Lists

    I had some time to work on the Linked List project. Code below. I was stuck on the concept of encapsulation for quiet awhile. I would make the sList class and then try to pass an sListNode Object to one of the sList's methods as a parameter. That seemed to defeat the purpose of encapsulation, finally I figured out that I did not need to pass an sListNode Object as a parameter, but only the "cargo" of that obect and just let the sList class handling creating the sListNode Objects as needed. I still have more methods to write for this class but I think I should not have to much trouble from this point.

    The sList class. All the methods that work with sListNode Objects are in this class. 3 have been written so far.

    The sListNode Class

    The code below just tests some of the methods of the sList class

  • Re: Linked Lists

    You state something about "garbage" being collected.

    I'm not an expert on the "VBA" and I'm pretty sure that .net employs a garbage collector ( memory cleaner ) but vba does not. The memory that loses the pointer to just sits there and is never returned to the portion of the memory HEAP that the instance runs in. ( Hence you will get memory leakage if this happens ) at least I believe it will.

    When you did your test for 1,000,000 nodes you might have ran out of memory that was allocated for your instance. I don't see a error handling around your "Set aNewNode = New sListNode" maybe if you do error checking when the "NEW" event fails you can cleanly abort execution without it crashing ...

  • Re: Linked Lists

    Thanks for pointing that out. I have a lot of GB's of RAM in this machine, I wonder how much memory could a million nodes take, or how much memory is typically allocated to an instance of Excel? I got the garbage collection reason from the video CS 61B on youtube, but that was for Java. For me the important thing was that you lose access to the rest of the linked list. How could error handling be set up for sInsertFront? I do not usually include error handling in my code.

    Also I see from the code that I was still having trouble with the concept of encapsulation when I posted it. The method sGetLastNode returns an sListNode which I now realize is not a good thing. I think it would have been helpful to clearly understand what the goal of the encapsulation was in the first place for this case - to prevent the user from having the ability to access any nodes at all in any way. As far as the user is concerned, they just want a list and some methods to manipulate the list. I think the method is supposed to be called sGetLastItem, not sGetLastNode, and it is supposed to return the "cargo" of the last sListNode, not the node itself.

  • Re: Linked Lists

    Here is the code that I have so far, minus commenting. There are 7 methods listed below


    sInsertFront seems to crash Excel if more than about 4000 nodes are inserted. If you have a for next loop with variable i, that keeps using sInsertFront, how would you trap the i when excel crashes?

    Sometimes I will get "Out of Stack Space" error before the crash. What are the limits of the Stack Space? If Instead of one sList node with say 30,000 nodes, would 10 sList nodes of 3000 nodes each prevent the stack space error?

    Other than that the code seems to work ok. I actually used it in a different program and was suprised how well it worked, it was useful.



    sList Class

  • Re: Linked Lists

    I forgot to mention, the method sGetNth was a difficult one for me to write. I tried to do the recursive solution that seems to be commonly taught. I could not find a way to do it unless I had a private helper function in order for the recursion to work. Any ideas suggestions to improve the code for any of the methods is appreciated. Also I know I a missing at least 2 common methods which I think are sInsertAfter and sInsertBefore. Any others?

  • Re: Linked Lists

    [FONT=&quot]It looks like it only crashes only if an individual sList Object contains more than about 2500 nodes. I was able to create a total of 25,000,000 sListNode objects contained in 10,000 sList Objects without excel crashing. I would guess that most data structures that use singly linked lists do not put thousands of data points within one sList object.[/FONT]

  • Re: Linked Lists

    I thought I would work on the Linked Lists project tonight and created 1 new method - sReverse. The sReverse method reverse the order of the linked list that sList points to, in other words it just reverse the order of a linked list. Not an easy method to write for some reason.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!