Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8408041
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T23:32:01+00:00 2026-06-09T23:32:01+00:00

This is my first post here, but I’m not new to the site (call

  • 0

This is my first post here, but I’m not new to the site (call me a lurker).
Unfortunately this time I cannot seem to find an answer to my question without asking.
Anyway, to the point.

I am writing a small snakes and ladders (aka chutes and ladders) program in java for a data structures course. I had to write my own Linked List (LL) class, (I know that there is a java util that does it better, but I have to learn about the workings of the data structure) and that is not a problem. My LL is ‘semi-Double linked’ as I like to call it, since it links forward, but has another pointer field for other links, which is not necessarily used in every node.

What I want to know is if it is possible to link a node from a list to another list, which is of a different type.
Poor example:
(eg.) How would one link a node of type to a node of type ? Let us say we have a LL of 7 int values [1,2,3,4,5,6,7], and a LL of 7 Strings [Monday, Tuesday, Wednesday,Thursday, Friday, Saturday, Sunday]. We want to link the node containing 1 to the node containing Monday.

To be exact the problem I am having is as follows:
I have 100 nodes forward-linked, forming the game board, and a circularly linked list of 4 . I want to link the player nodes to their respective positions on the board, so that as they traverse the board, they can also follow the “snakes” and “ladders” links.

Thanks in advance!

My LLNode.java and LL.java are attached.

// LLNode.java  
// node in a generic linked list class, with a link 

public class LLNode<T> 
{
    public T info;
    public LLNode<T> next, link;

    public LLNode()
    {   
        next = null;
        link= null;
    }

    public LLNode(T element)
    {
        info = element;
        next = null;
        link = null;
    }

    public LLNode(T element, LLNode<T> n)
    {
        info = element;
        next = n;
        link = null;
    }

    public T getInfo()
    {
        return info;
    }

    public void setInfo(T element)
    {
        info = element;
    }

    public LLNode<T> getNext()
    {
        return next;
    }

    public void setNext(LLNode<T> newNext)
    {
        next = newNext;
    }

    public LLNode<T> getLink()
    {
        return link;
    }

    public void setLink(LLNode<T> newLink)
    {
        link = newLink;
    }
}

// SLL.java 
// a generic linked list class

public class LL<T> 
{
    private LLNode<T> head, tail;
    public LLNode<T> current = head;

    public LL()
    {
        head = tail = null;
    }

    public boolean isEmpty()
    {
        return head == tail;
    }

    public void setToNull()
    {
         head = tail = null;
    }

    public boolean isNull()
    {
        if(head == tail)
            if(head == null || tail == null)
                return true;
            else 
                return false;
        else 
            return false;
    }

    public void addToHead(T element)
    {
        head = new LLNode<T>(element, head);
        if (tail == null)
            tail = head;
    }

    public void addNodeToHead(LLNode<T> newNode)
    {
        head = newNode;
        if (tail == null)
            tail = head;
    }

    public void addToTail(T element)
    {
        if (!isNull())
        {
            tail.next= new LLNode<T>(element);
            tail = tail.next;
        }
        else head = tail = new LLNode<T>(element);
    }

    public void addNodeToTail(LLNode<T> newNode)
    {
        if (!isNull())
        {
            tail.next= newNode;
            tail = tail.next;
        }
        else head = tail = newNode;
    }

    public void addBefore(T element, T X)
    {
        if (!isEmpty()) // Case 1
        {
            LLNode<T> temp, n;

            temp = head;
            while( temp.next != null )
            {
                if( temp.next.info == X )
                {
                    n = new LLNode<T>(element, temp.next);
                    temp.next = n;
                    return;
                }
                else 
                temp = temp.next;
            }    
        }
        else // Case 2
            head = new LLNode<T>(element, head);
    }

    public void addBefore(T element, LLNode<T> X)
    {
        if (!isEmpty()) // Case 1
        {
            LLNode<T> temp, n;

            temp = head;
            while( temp.next != null )
            {
                if( temp.next == X )
                {
                    n = new LLNode<T>(element, X);
                    temp.next = n;
                    return;
                }
                else 
                temp = temp.next;
            }    
        }
        else // Case 2
            head = new LLNode<T>(element, head);
    }

    public T deleteFromHead()
    {
        if (isEmpty())
            return null;
        T element = head.info;
        if (head == tail)
            head = tail = null;
        else head = head.next;
        return element;
    }

    public T deleteFromTail()
    {
        if (isEmpty())
            return null;
        T element = tail.info;
        if (head == tail)
            head = tail = null;
        else 
        {
            LLNode<T> temp;
            for (temp = head; temp.next != tail; temp = temp.next);
            tail = temp;
            tail.next = null;
        }
        return element;
    }

    public void delete(T element)
    {
        if (!isEmpty())
            if (head == tail && (element.toString()).equals(head.info.toString()))
                head = tail = null;
            else if ((element.toString()).equals(head.info.toString()))
                head = head.next;
        else 
        {
            LLNode<T> pred, temp;
            for (pred = head, temp = head.next; temp != null && !((temp.info.toString()).equals(element.toString())); pred = pred.next, temp = temp.next);
            if (temp != null)
                pred.next = temp.next;
            if  (temp == tail)
                tail = pred;
        }
    }

    public void listAll()
    {
        if(isNull())
            System.out.println("\tEmpty");
        else
        {
            for ( LLNode<T> temp = head; temp!= tail.next; temp = temp.next)
                System.out.println(temp.info);
        }
    }

    public LLNode<T> isInList(T element)
    {
        LLNode<T> temp;
        for ( temp = head; temp != null && !((temp.info.toString()).equals(element.toString())); temp = temp.next);
        return temp ;
    }

    public LLNode<T> getHead()
    {
        return head;
    }

    public LLNode<T> getTail()
    {
        return tail;
    }

    public LLNode<T> getCurrent()
    {
        return current;
    }

    public void incrementCurrent()
    {
        current = current.next;
    }

    public void followCurrentLink()
    {
        current = current.link;
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T23:32:03+00:00Added an answer on June 9, 2026 at 11:32 pm

    Any specific reason you want to generics for the specific problem domain of the node objects?

    If you want to have this effect, another way to do it might be have an interface for node object (maybe call it ILinkNode), have the getInfo and setInfo overridden in two different node classes. Then the nodeLink can point to interface object without special type casting everywhere in the code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

my first post here. I'm not new to JQuery, but I find complex coding
This is my first post here, but I've using this site regularly to help
I'm new to Java and this is my first post on here so hopefully
This is my first time here so I hope I post this question at
this is my first post here. First off, some background, I'm new to C#
this is my first post here. I'm new in Android Programming. I want to
this is my first ever post here. I'm not sure if I've done the
This is my first post on here and I'm very new to iPhone developing,
this is my first post here. I'm using an existing Flash widget but would
this is my first post here but I've been a frequent reader of various

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.