I’m facing a real problem in understanding how to draw a variable diagram to a linked list
In the book I’m reading its not giving enough info
I will post an example:
the insert:
public void Insert(Object newItem, Object after) { Node current = new Node(); Node newNode = new Node(newItem); current = Find(after); newNode.Link = current.Link; current.Link = newNode; } private Node FindPrevious(Object n) { Node current = header; while(!(current.Link == null) && (current.Link.Element != n)) current = current.Link; return current; } public void Remove(Object n) { Node p = FindPrevious(n); if (!(p.Link == null)) p.Link = p.Link.Link; }
I’ve searched the net for more info but each time I found different info can anyone help please
Are you trying to draw it out on paper for homework? If so, the Link property of each node has a reference to the next node in the linked list. To draw it, you would probably have a series of boxes in a row that represent the node classes. In each node, you would have two properties, the Item and the Link. Link would point to the next node in the chain and Item would point to the item outside the list.
The code you provide looks like a singly linked list. See the Wikipedia page on linked lists for an example and a simple diagram. In that example, the numbers are the data in the linked list (your items) and the dots with the arrows are your links to the next item in the list (the Link property.)
Hope this is what your looking for. Otherwise, please revise your question.