• 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

need help

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i m new to java and i m learning the basics . i want to create some nodes and connect them with link(edge). each node should contain information of other nodes.can anyone help me plz.
thanks
 
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Check out the LinkedList class for this sort of behavior. If this is a class assignment then your teacher probably wants you do implement the Linked List yourself (and not use the built in class). In that case you don't need any more info other than how to create classes and manage references between them.

_M_
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, welcome to the ranch!

In a few words here are some structures that might be what you're looking for. I was a music major, not CS, so the names may not be what your instructor or the other ranchers call them ...

Linked list: Each node holds something interesting and a reference to another node often called "next". You keep a reference to the first one. To get to any other node you follow the "next" pointers. The last node in the list has next == null or sometimes points back to the first one for a "circular" list.

Doubly linked list: Liked linked list but also has a reference to "prior". You can work your way back and forth in the list.

Binary tree: Each node holds a key and a value, a reference to another node whose key is "less than" this one, and a reference to a node whose key is "more than" this one. These references are often called "left" and "right". To find a given key you start at the top. If the node's key is greater than the one you want you go left, if the node's key is less than the one you want you go right.

Tree: Each node hods a value and a collection of any number of references to child nodes. You get this kind of thing when you parse XML or HTML.

Most of these structures are provided for you in the standard libraries. But it is great fun and education to build your own. Try a linked list. See if you can add new nodes to the end, print them all out, insert or delete nodes in the middle. If you want to give it a try, the "ranch way" is to give it a try and if you get stuck show us what you made so far.

Have fun!
 
reply
    Bookmark Topic Watch Topic
  • New Topic