Hi,
I found a source code from http://dotnetperls.com/linkedlist.
I wanna do something like them regarding the linkedlistnode.
Below is the code:-
--- Output of the program ---
one
inserted
two
three
***
Then, I follow their code and some error occur. Below is my code:-
Error occur at line 23. Can someone help me... Thx n appreciate it...
The output should be:-
kfr
tfr
sfr
I found a source code from http://dotnetperls.com/linkedlist.
I wanna do something like them regarding the linkedlistnode.
Below is the code:-
Code:
using System;
using System.Collections.Generic;
class Program
{
static void Main()
{
//
// Create a new linked list.
//
LinkedList<string> linked = new LinkedList<string>();
//
// First add three elements to the linked list.
//
linked.AddLast("one");
linked.AddLast("two");
linked.AddLast("three");
//
// Insert a node before the second node (after the first node)
//
LinkedListNode<string> node = linked.Find("one");
linked.AddAfter(node, "inserted");
//
// Loop through the linked list.
//
foreach (var value in linked)
{
Console.WriteLine(value);
}
}
}
one
inserted
two
three
***
Then, I follow their code and some error occur. Below is my code:-
Code:
using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Text;
class Program
{
public static void Main(string[] args)
{
LinkedList<addall1> addorder1 = new LinkedList<addall1>();
string foodname1 = "kfr";
addall1 a1 = new addall1(1, foodname1);
addorder1.AddLast(a1);
string foodname2 = "sfr";
addall1 a2 = new addall1(1, foodname2);
addorder1.AddLast(a2);
string foodname3 = "tfr";
LinkedListNode<addall1> node = addorder1.Find(foodname1);
addorder1.AddAfter(node,(1,foodname3));
foreach(addall1 ad1 in addorder1)
{
Console.WriteLine("Qty:" + ad1.Countb4sol + " Name:" + ad1.Llfdname1);
}
Console.ReadLine();
}
public class addall1
{
public addall1(int countb4sol1, string llfdname1)
{
_countb4sol1 = countb4sol1;
_llfdname1 = llfdname1;
}
private int _countb4sol1;
private string _llfdname1 = "";
public int Countb4sol
{
get { return (_countb4sol1); }
set { _countb4sol1 = value; }
}
public string Llfdname1
{
get { return (_llfdname1); }
set { _llfdname1 = value; }
}
}
}
The output should be:-
kfr
tfr
sfr
Comment