This program is basically the same program as 3L, but the implementation will be static rather than dynamic. In this case, all the linked lists will be taken from a single array of nodes defined as static member data. Dll.StaticCls.cpp should be of considerable use. Your static member data array should allocate 60 nodes. Convert your existing functions to deal with the nodes in the array. Add methods deleteNode and newNode that mirror delete and new. You should initially place all the nodes in the array in the "freelist", which may be linked how ever you please.
ok, now in this, so i would have a static member data array like the following...
all i really want to know is, all im doing is allocating memory in an array, for my nodes, instead of letting the OS do it for me right?
so everytime i call newNode, it just takes the first node reference at theNodes[freelist] and assign that spot in the array to what ever node I create, then freelist = theNodes[freelist].next;
where freelist points to the first node reference in the "theNodes" array;
but even though im creating my nodes in the array in order? can I still modify next and prev to what ever node I want, or do i need to create the node and insert it in order into the "theNodes" array?
Originally posted by Justin Fox: ...all i really want to know is, all im doing is allocating memory in an array, for my nodes, instead of letting the OS do it for me right?
Yes, new Node creates an array object containing 60 Node references -- all initialized to null at this stage. In contrast to something that can be dynamically resized like a List, this array's size is now set and won't be changing. (Note: I think you mean the VM instead of the OS.)
Originally posted by Justin Fox: ...can I still modify next and prev to what ever node I want, or do i need to create the node and insert it in order into the "theNodes" array?
The array is just a place to store references to Node instances. The "next" and "prev" instance variables in a Node have nothing to do with that Node's position in the array. For example, the Node at index 3 might have a "next" value of 11 and a "prev" value of 49. The key here is that you can randomly access array elements, so jumping from 49 to 3 to 11 should be no problem. [ July 15, 2006: Message edited by: marc weber ]
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer sscce.org
Joined: Jan 24, 2006
Joined: Jan 24, 2006
ok in the following program, i need to initially link the nodes in the array theNodes, but how do i go about doing that when you cant do it outside a constructor, and a non-static method can't call a static method..
It would help if you provide some context (I don't see these lines anywhere in the 356 lines of code you posted earlier), along with the exact error message.
My guess is that these lines are inside a static method, and you are getting an error like...
In the context of your original code, Node is an inner class of StaticDDLL. An inner class is simply a nested class that is not static. Because they're not static, instances of inner classes are tied to an instance of the enclosing class. And in this context, when you say "new Node()," the implication is "this.new Node()," where "this" references an instance of the enclosing class. But in a static context, there is no "this" reference, which should explain the error message. [ July 17, 2006: Message edited by: marc weber ]
Joined: Jan 24, 2006
ok in the very beginning of my StaticDDLL class, i import Scanner and io
im getting this error,
umm i'm most definately positive that you're supposed to capitalize the 's' on scanner.
Originally posted by Justin Fox: I believe so, i mean, I'm using the univerities computers in the Computer Science Labs, would think they'd be up to date...
its using... (jdk1.5.0_06)...
Are you sure? At the command prompt, try typing "javac -version" (without the quotes). You will get a long error message for not including a source file, but the compiler version should appear at the top...