CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2013
    Posts
    1

    Linked Lists Java Programming HELPP P.S. I am a beginner in Java Programming

    How do I create an application that uses a linked list. You must be able to do at least the following to the linked list:

    check whether the list is empty
    display the list
    find the length of the list
    destroy the list
    retrieve the data in the nth node
    search the list for a given item
    insert an item in the list
    delete an item from the list

    Thanks

  2. #2
    Join Date
    May 2009
    Posts
    2,413

    Re: Linked Lists Java Programming HELPP P.S. I am a beginner in Java Programming

    Quote Originally Posted by judemartin99 View Post
    How do I create an application that uses a linked list.
    A (singly) linked list consists of nodes that usually look something like this,

    Code:
    class Node {
       Data data;
       Node next;
    }
    Each node holds some data. In the simplest case it could be an int. And each node is linked to the next node by holding a reference to it.

    Then you need to come up with all the wanted operations on these linked nodes. Most involve you "walk" the chain of next references from the first up to the last node at the most (the one with a null next reference) and do something along the way. It could be you count the nodes to get the list length or you add a new node when you reach the end. Or you add it at the very beginning for that matter because it obviously is more efficient.
    Last edited by nuzzle; March 29th, 2013 at 05:52 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
  •  





Click Here to Expand Forum to Full Width

Featured