DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2007
    Posts
    9

    single linked list.. so confused...

    hi! i need to make a program using a single link list... i have to store information on motorbikes wherein each motorbike contain brand, price, etc... I have no idea how to do this.. I can do this using array but not with link list.. i only know a bit about single link list and i don't have any idea where to start.. should i make a class that contains those info like brand and price? but i am supposed to make a linked list.. i've been trying to study linked list for like ages now and i don't still know how to start with the program.. i cud probably do the adding, and deleting nodes from the linked list.. but how about those information about brand and prices?.. badly need help... i need this 2 days from now... pls...

  2. #2
    Join Date
    Dec 2004
    Location
    San Bernardino County, California
    Posts
    1,468
    One approach is to use a Node class, which has a "next" data field, which will hold a reference to the node which is "next" in the linked list. Your node can also have the information about motorbikes as a part of the class, or it can hold an instance of a Motorbike class (more OOP like).

    There is a lot of code available on the Internet - Google
    "java linked list goodrich" and some good stuff will return

  3. #3
    Join Date
    Mar 2007
    Posts
    9
    i am not getting what u said about the node having information about motorbikes..
    should the Node class look like this?

    class Node{
    private String value;
    private Node next;
    private String plate;
    private String brand;
    private int price;
    private int speed;
    }
    public Node(String s, node n, String p, String b, int pr, int sp){
    value =s;
    node =n;
    plate=p;
    brand=b;
    price=pr;
    speed=sp;
    }

    //accessors and mutators here...


    is that it? or am i wrong?

  4. #4
    Join Date
    Dec 2004
    Location
    San Bernardino County, California
    Posts
    1,468
    either set it up as

    class Node
    {
    private Motorbike bike;
    private Node next;

    public Node( Motorbike bike; Node next )
    {
    this.bike = bike;
    this.next = next;
    }

    and various methods here

    }

    or
    class Node{
    private Node next;
    private String plate;
    private String brand;
    private int price;
    private int speed;
    etc.
    }

Similar Threads

  1. Linked List Error
    By Dark Rain in forum C++
    Replies: 11
    Last Post: 02-18-2007, 12:06 PM
  2. Replies: 1
    Last Post: 11-04-2005, 06:19 AM
  3. Problem with linked lists and iterators
    By white94cam in forum C++
    Replies: 2
    Last Post: 03-30-2005, 11:02 PM
  4. How long before the next version??
    By _CAG in forum .NET
    Replies: 146
    Last Post: 08-12-2002, 10:40 PM
  5. Re: App Object (fixes)
    By Rob Teixeira in forum .NET
    Replies: 129
    Last Post: 06-06-2002, 05:23 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links