Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

asterisk in variable names or bash-style "wildcard" iteration through variable names

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello CodeRanch,

I am learning about multi-linked lists and graphs and I was thinking about how to implement a multi-linked list where each node had a variable number of pointers.  However, after thinking about writing a boolean exists(pointer) method, I realized that I couldn't iterate through some numbers of variable names.  

Psuedo-code:



But I realized this was a bash-style method, not Java.  However- in looking up pointers, this geeksForGeeks article repeatedly uses asterisks in variable names.  I am having a hard time finding any information as to why this is done or what it means- does anyone here know?

Thank you,
Casey
 
Marshal
Posts: 75646
354
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Casey Jayne wrote:. . .. . .

Please shorten that toSee the old Sun Style Suggestions. The sort of names with $ and * and {} in can only be used in Bash, etc.
 
Saloon Keeper
Posts: 25461
180
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First of all, Java does not have "pointers". Despite the fact that it has a "NullPointerException". Java works with references, and while you can use pointers to reference stuff, references themselves are not pointers in Java.

A multi-node list element with named "pointers", however, is not a good fit for Java. It could be done in several ways, including having the list node paired with a Map of named references, but that's a bit of overhead.

More commonly one would have the node associated with an object array and use integer value indexing. You could then use a Java Iterator, a for-each, or one of the newer language constructs to pass over the array's elements.

You could also associate a List node with a Collection. Which is what the Node-with-Map solution I iniitally suggested does.

Then again, you can do a lot with binary and trinary trees and simply use an existing library.
 
Casey Jayne
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Holloway wrote:First of all, Java does not have "pointers". Despite the fact that it has a "NullPointerException". Java works with references, and while you can use pointers to reference stuff, references themselves are not pointers in Java.



Thank you for clarifying. Our professor calls the references pointers, but I didn't realize this was not great terminology for expressing the utility.

Tim Holloway wrote:
A multi-node list element with named "pointers", however, is not a good fit for Java. It could be done in several ways, including having the list node paired with a Map of named references, but that's a bit of overhead.

More commonly one would have the node associated with an object array and use integer value indexing. You could then use a Java Iterator, a for-each, or one of the newer language constructs to pass over the array's elements.

You could also associate a List node with a Collection. Which is what the Node-with-Map solution I iniitally suggested does.

Then again, you can do a lot with binary and trinary trees and simply use an existing library.



Thanks for explaining that- we aren't allowed to use any existing libraries except java.IO, so we have to build our own structures.  I'm curious how a multilinked list could use an integer array, do you mean so that each array element held the number of pointers/links for the associated nodes?
 
Tim Holloway
Saloon Keeper
Posts: 25461
180
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here's an example of why a "reference" isn't necessarily a pointer.

On the original Macintosh OS, objects were accessed via "handles", not pointers. A pointer, strictly speaking, is an absolute memory address - or in some cases, a displacement from an absolute base address (like in the 80286 segmented memory architecture). Handles were actually pointers to pointers and they made it possible to easily compact memory since you could move the object around and change the handle's contents without changing the value of the handle itself, thus making the memory movement transparent to the applications. You can also use short handles to long pointers, relative handles, hash pointers and many other tricks. In the JVM, any of those schemes would be acceptable, since the actual implementation is internal to the JVM and not reflected in explicit primitive values in Java code. You cannot, for example, do pointer addition or offsetting in Java like you can in C. The closest you can get is an array index, and that requires an array (which is an object, and thus located via a reference!) and a valid array index value (>=0 and < array.length).

If I know the number of integers a given node will host, I can simply say "myNode.reserveSlots(n)" or node constructor where slot allocation is implemented as "this.slots = new Integer[n];" and then I'd know how many slots that node supported, since it would be the node's "this.slots.length" property. If I wanted a dynamically variable number of slots, I could define slots as an ArrayList and use its length() method (note that length of an array is a property and not a method call, unlike ArrayList).
 
Casey Jayne
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you, Tim, for that explanation- it helps a lot.  I think it will take me awhile to understand fully but I'm going to flag this to keep referring to as I'm working with them.  
 
And inside of my fortune cookie was this tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic