'LinkedList C# (data structures and algorithms using C# michael mcmillan )
I found This Code in a Book (data structures and algorithms using C# michael mcmillan )to do a linkedlist but i cant understand what is object after and why do we use find method and when i put it in vsc it gave me error.
(error CS1061: 'Node' does not contain a definition for 'header' and no accessible extension method 'header' accepting a first argument of type 'Node' could be found)
public class Node
{
public Object Element;
public Node Link;
public Node()
{
Element = null;
Link = null;
}
public Node(Object theElement)
{
Element = theElement;
Link = null;
}
}
class LinkedList
{
protected Node header;
public LinkedList()
{
header = new Node("header");
}
private Node Find(Object item)
{
Node current = new Node();
current = header;
while(current.header !=item) //i cant understand this line page 198 in the book
current = current.Link;
return current;
}
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;
}
}
Solution 1:[1]
public Node Find(Object item)
{
Node current = new Node();
current = header;
while (!object.Equals(Current.Element, Item) && Current.Link !=null)
current = current.Link;
return current;
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Lukasz Szczygielek |
