• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Static Doubly Linked Lists....

 
Ranch Hand
Posts: 802
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok here is the assignment description...

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?

thanks,
justin
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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[60] 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 ]
 
Justin Fox
Ranch Hand
Posts: 802
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks dude!
 
Justin Fox
Ranch Hand
Posts: 802
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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..

code:


[ July 17, 2006: Message edited by: Justin Fox ]
 
marc weber
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Justin Fox:
...a non-static method can't call a static method...




A non-static (instance) member cannot be accessed from a static context, but the reverse is not true.
 
Justin Fox
Ranch Hand
Posts: 802
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok, i have the static memeber data Node[] theNodes = new Node[60];

i need to modify the next pointer to be the next index of the current.

for example:

theNodes[0].nextNum = 1;

so that the node at index 0 points to 1 and 1 points to 2 and so on

but the Node[] is static, so i can't

say


i get a static/non-static conflict....

plz help,
Justin
 
marc weber
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Justin Fox
Ranch Hand
Posts: 802
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok in the very beginning of my StaticDDLL class, i import Scanner and io

like so:


im getting this error,



umm i'm most definately positive that you're supposed to capitalize the
's' on scanner.

help plz,
Justin
 
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you using JDK1.5 ? Scanner didn't exist in earlier versions.
 
Justin Fox
Ranch Hand
Posts: 802
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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)

so... I don't know what the deal is...

justin
 
marc weber
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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...
 
reply
    Bookmark Topic Watch Topic
  • New Topic