TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
LinkedList Example In C#
Soumalya Das
Aug 29
2016
Code
2.5
k
0
4
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
namespace Consolepractice {
class
Program {
public
static
void
Main(string[] args) {
document d1 =
new
document() {
docname =
"C# tutorial"
,
doctype =
"PDF"
};
document d2 =
new
document() {
docname =
"Java tutorial"
,
doctype =
"Word"
};
document d3 =
new
document() {
docname =
"SQl tutorial"
,
doctype =
"Word"
};
document d4 =
new
document() {
docname =
"HTML tutorial"
,
doctype =
"Word"
};
document d5 =
new
document() {
docname =
"CSS tutorial"
,
doctype =
"PDF"
};
document d6 =
new
document() {
docname =
"Jquery tutorial"
,
doctype =
"PDF"
};
PrintQue ob =
new
PrintQue();
Console.WriteLine(
"Adding document operation start....\n \n"
);
//add node at last position
ob.Addlast(d1);
ob.Addlast(d2);
//add node at first position
ob.AddFirst(d3);
//add node before d1 node
ob.AddBefore(d1, d4);
//add node after d1 node
ob.AddAfter(d1, d5);
//add node at last position
ob.Addlast(d6);
foreach(
var
item
in
ob.lnk) {
Console.WriteLine(
"Document nae:{0} and doctype:{1}"
, item.docname, item.doctype);
}
Console.WriteLine(
"\nAfter remove document operation ....\n \n"
);
ob.RemoveFirst();
//remove first node
ob.RemoveLast();
//remove last node
ob.Removenode(d5);
//remove Css tutorial node
foreach(
var
item
in
ob.lnk) {
Console.WriteLine(
"Document nae:{0} and doctype:{1}"
, item.docname, item.doctype);
}
Console.ReadKey();
}
}
class
PrintQue {
public
LinkedList < document > lnk =
new
LinkedList < document > ();
public
void
Addlast(document node) {
lnk.AddLast(node);
}
public
void
AddFirst(document node) {
lnk.AddFirst(node);
}
public
void
AddBefore(document node, document newnode) {
lnk.AddBefore(lnk.Find(node), newnode);
}
public
void
AddAfter(document node, document newnode) {
lnk.AddAfter(lnk.Find(node), newnode);
}
public
void
RemoveFirst() {
lnk.RemoveFirst();
}
public
void
RemoveLast() {
lnk.RemoveLast();
}
public
void
Removenode(document node) {
lnk.Remove(node);
}
}
class
document {
public
string docname;
public
string doctype;
}
}
LinkedList example
C#