single linked list.. so confused...


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: single linked list.. so confused...

  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, 01:06 PM
  2. Replies: 1
    Last Post: 11-04-2005, 07:19 AM
  3. Problem with linked lists and iterators
    By white94cam in forum C++
    Replies: 2
    Last Post: 03-31-2005, 12:02 AM
  4. How long before the next version??
    By _CAG in forum .NET
    Replies: 146
    Last Post: 08-12-2002, 11:40 PM
  5. Re: App Object (fixes)
    By Rob Teixeira in forum .NET
    Replies: 129
    Last Post: 06-06-2002, 06:23 AM

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


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center