Add to Favorites    Make Home Page 198 Online  
 Language Categories  
 Our Services  

Get 9,000 Interview Questions & Answers in an eBook.


  • 9500+ Pages
  • 9000 Question & Answers
  • All Tech. Categories
  • 14 MB Content

    Get it now !!



    Send your Resume to 6000 Companies


  • Java Data Structures - Contents


    Nodes...

    A D V E R T I S E M E N T

    Attention: Free eWeek Magazine Subscription. Absolutely Free!

    Search Projects & Source Codes:

        The other type of data structures are what's called Node based data structures. Instead of storing data in it's raw format, Node based data structures store nodes, which in turn store the data. Think of nodes as being elements, which may have one or more pointers to other nodes.

        Yes, I did say the "pointer" word. Many people think that there are no pointers in Java, but just because you don't see them directly, doesn't mean they're not there. In fact, you can treat any object as a pointer.

        Thus, the Node structure should have a data element, and a reference to another node (or nodes). Those other nodes which are referenced to, are called child nodes. The node itself is called the parent node (or sometimes a "father" node) in reference to it's children. (nice big happy family)

        Well, the best way to visualize a node is to create one, so, lets do it. The node we'll create will be a one child node (it will have only one pointer), and we'll later use it in later sections to build really cool data structures. The source for our one child node follows:

    public class pOneChildNode{
        protected Object data;
        protected pOneChildNode next;
    
        public pOneChildNode(){
            next = null;
            data = null;
        }
        public pOneChildNode(Object d,pOneChildNode n){
            data = d;
            next = n;
        }
        public void setNext(pOneChildNode n){
            next = n;
        }
        public void setData(Object d){
            data = d;
        }
        public pOneChildNode getNext(){
            return next;
        }
        public Object getData(){
            return data;
        }
        public String toString(){
            return ""+data;
        }
    }

        Go over the source, notice that it's nothing more than just set and get functions (pretty simple). The two data members are the data and next. The data member holds the data of the node, and next holds the pointer to the next node. Notice that next is of the same type as the class itself; it effectively points to the object of same class!

        The String toString() method is the Java's standard way to print things. If an object wants to be printed in a special way, it will define this method, with instructions on how to print this object. In our case, we just want to print the data. Adding data to a bunch of quotation marks automatically converts it to type String (hopefully, our data will also have a toString() method defined on it). Without this method, we get the actual binary representation of the data members of this class (not a pretty nor meaningful printout).

        Node based data structures provide for dynamic growing and shrinking, and are the key to some complex algorithms (as you'll see later). Now that we know how to implement a Node, lets get to something cool...


    Back to Table of Contents


    A D V E R T I S E M E N T




    Google Groups Subscribe to SourceCodesWorld - Techies Talk
    Email:

    Free eBook - Interview Questions: Get over 1,000 Interview Questions in an eBook for free when you join JobsAssist. Just click on the button below to join JobsAssist and you will immediately receive the Free eBook with thousands of Interview Questions in an ebook when you join.

     Advertisements  

     Free Magazines

    Jobs & Career
    Freshers Jobs
    Jobs Newsletter
    Placement Papers
    Placement Papers
    GATE Preparation
    Analysis & Design Of Algo.
    Operating System
    Lexical Analysis
    GRE Preparation
    GRE Home
    1208 Antonyms Test
    5000 Word's List
    Top 100 Words' List
    Scholarships
    Top 100 CS Univ.
    Top 126 EE Univ.
    Tutorials
    Hardware Tutorial
    1500 Free eBooks
    XML Tutorial
    Webmaster Resources
    EzTraffic
    Articles
    Fun
    Send FREE SMS!
    SMS Jokes
    Love SMS
    Funny Jokes

    Google Search

    Google

    Source Codes World.com is a part of Vyom Network.

    Vyom Network : Free SMS, GRE, GMAT, MBA | Online Exams | Freshers Jobs | Software Downloads | Interview Questions | Delhi Info | Jobs, Discussions | Placement Papers | Free eBooks | Free eBooks | Free Business Info | Interview Questions | Free Tutorials | Arabic, French, German | IAS Preparation | Jokes, Songs, Fun | Free Classifieds | Free Recipes | Free Downloads | Bangalore Info | Tech Solutions | Project Outsourcing, Web Hosting | GATE Preparation | MBA Preparation | SAP Info | Software Testing | Google Logo Maker | Freshers Jobs

    Sitemap | Privacy Policy
    Copyright ©2003-2006 Vyom Technosoft Pvt. Ltd., All Rights Reserved.
    Page URL: http://www.sourcecodesworld.com/articles/java/java-data-structures/Nodes.asp


    Download Yahoo Messenger | Placement Papers | Free SMS | C Interview Questions | C++ Interview Questions