1

Can I have this kind of a structure in a linked list?

public class myLinkedList{
myLinkedList parent;
String data;
myLinkedList[] next;
}

The problem is, this node might or might not have multiple connections.

Thanks!

4
  • 2
    Yes, you can. The next array can have multiple values, including none. Is the question just that? Commented May 25, 2013 at 4:34
  • Yes. I know that nodes of a Linked List get stored in the heap. But I wasn't sure if an already created node could have more memory locations allocated. Commented May 25, 2013 at 4:46
  • You can "remake" the array at any time just by assigning a new one: next = new myLinkedList[99]; next = new myLinkedList[1]; next = new myLinkedList[30];. Keep in mind we are assigning a brand new array here everytime, not expanding its size. If you need dynamic size, you should go for a Collection like ArrayList. Commented May 25, 2013 at 4:49
  • 1
    that way It can be either a tree, a topology, or a FSM Commented May 25, 2013 at 5:13

2 Answers 2

3

The language allows your class to hold your reference next to the mylinkedlist array.

However, a linked list is linear. Your structure may be a tree or a graph.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you. I understood what I am doing here. I have been studying a lot of Linked List and I keep thinking in those terms. You are right. This is a graph problem that I am working on.
1

Singley-linked lists, by definition, have one connection (pointer to the next node). Doubley-linked lists have two (one pointing to previous node, the other pointing to the next node). If you are going to have multiple connections, you should use a tree, or a graph.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.