Results 1 to 2 of 2
  1. #1
    Clown is offline Member
    Join Date
    Mar 2010
    Posts
    9
    Rep Power
    0

    Default Java double linked list

    Hi huys just wanted to ask if I can use int array as the element of a double linked list. In the constructor below all elements are from Integer type. The problem is that I need to save two ints in one "inhalt"( one for the element itself and one for the reference).

    Thanks in advance.

    public class Liste<Integer>
    {

    private Liste <Integer> praefix;
    private Integer inhalt;
    private Liste <Integer> suffix;


    public Liste(Integer e) {
    inhalt = e;
    praefix = null;
    suffix = null;
    }

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,368
    Blog Entries
    7
    Rep Power
    20

    Default

    That class would make a fine node of a double linked list; just change your notation somewhat:

    Java Code:
    public class Liste<T>
    {
    
        private Liste <T> praefix;
        private T inhalt;
        private Liste <T> suffix;
       
        public Liste(T e) {
            inhalt = e;
            praefix = null;
            suffix = null;
       }
    }
    That way the type of the data is T and you can always 'specialize' that type:

    Java Code:
    Liste <Integer> head= new Liste<Integer>(new Integer(42));
    kind regards,

    Jos

Similar Threads

  1. Linked list inside a linked list
    By viperlasson in forum New To Java
    Replies: 5
    Last Post: 07-26-2010, 11:15 PM
  2. Linked List
    By basma in forum JCreator
    Replies: 0
    Last Post: 02-03-2010, 08:34 AM
  3. Circular Double Linked List
    By theonly in forum Advanced Java
    Replies: 3
    Last Post: 12-06-2009, 05:10 PM
  4. Linked list
    By rosh72851 in forum New To Java
    Replies: 1
    Last Post: 02-05-2009, 07:21 AM
  5. Linked List integer list
    By igniteflow in forum Advanced Java
    Replies: 1
    Last Post: 12-10-2008, 08:53 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •