So I'm creating a LinkedList in C# winforms, and now I want to display the list visually when adding, removing and searching for node values. I use 3 button controls, one for adding nodes, removing nodes and the last for searching for a nodes value. Then, I have a textbox that should read in a int value from user (ex. 10), and then display that value as a linked list, in a Listbox. So, Ive created a Node class and a linkedlist class. The Node class holds a value and a reference to the next node:
class Node
{
public int value;
public Node next;
public int Value
{
get { return this.value; }
set { this.value = value; }
}
public Node Next
{
get;
set;
}
public Node()
{
this.Next = null;
this.value = 0;
}
}
and a LinkedList class with all my methods (I will only write my add method, so It wont be too much code)
public void Add(int val)
{
Node newNode = new Node();
newNode.value = val;
if (head == null)
head = newNode;
if (current.Next == null)
{
current.Next = newNode;
current = newNode;
}
size++;
}
So, Now what imm trying to Do is to write some code so that when I input a int number in the textbox, it should appear in the Listbox as a LinkedList (with my add method from my LinkedList class)
I tried to do this on the event handler for my Add button:
LinkedList l1 = new LinkedList();
l1.Add(textBox1);
But clearly that is not even logical. Could someone please point me to the right direction here?