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
Implementation Of Linked Lists Using Collections Name Space In C#
Vijayaragavan S
Aug 24
2016
Code
718
0
0
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
using
System;
using
System.Collections.Generic;
namespace
LinkList {
class
Program {
static
LinkedList <
int
> ll =
new
LinkedList <
int
> ();
static
LinkedListNode <
int
> node;
static
void
Main(
string
[] args) {
Console.WriteLine(
" LINKED LIST DEMO"
);
int
ch, x;
Console.WriteLine(
"Linked List Operations"
);
Console.WriteLine(
"1.AddFirst\n2.AddLast\n3.RemoveFirst\n4.RemoveLast\n5.Remove Specified\n6.Display\n7..Exit"
);
while
(
true
) {
Console.Write(
"Enter your Choice : "
);
ch = Convert.ToInt16(Console.ReadLine());
switch
(ch) {
case
1:
Console.Write(
"Enter the Element to AddFirst : "
);
x = Convert.ToInt16(Console.ReadLine());
ll.AddFirst(x);
display();
break
;
case
2:
Console.WriteLine(
"Enter the Element to AddLast : "
);
x = Convert.ToInt16(Console.ReadLine());
ll.AddLast(x);
display();
break
;
case
3:
if
(ll.Count == 0) {
Console.WriteLine(
"Nothing to Delete...!!!"
);
break
;
}
else
{
Console.WriteLine(
"First Element Removed Successfully"
);
ll.RemoveFirst();
display();
break
;
}
case
4:
if
(ll.Count == 0) {
Console.WriteLine(
"Nothing to Delete...!!!"
);
break
;
}
else
{
Console.WriteLine(
"Last Element Removed Successfully"
);
ll.RemoveLast();
display();
break
;
}
case
5:
if
(ll.Count == 0) {
Console.WriteLine(
"Nothing to Delete...!!!"
);
break
;
}
else
{
Console.WriteLine(
"Enter the Element to Remove"
);
x = Convert.ToInt16(Console.ReadLine());
bool
b = ll.Remove(x);
if
(b ==
true
) {
Console.WriteLine(
"Element Removed Successfully"
);
display();
break
;
}
else
{
Console.WriteLine(
"Specified Node Does not Exist"
);
break
;
}
}
case
6:
display();
break
;
default
:
Environment.Exit(0);
break
;
}
}
}
public
static
void
display() {
if
(ll.Count == 0) {
Console.WriteLine(
"Nothing to Display...!!!"
);
}
else
{
Console.Write(
"Elements in the List are:"
);
for
(node = ll.First; node !=
null
; node = node.Next) Console.Write(node.Value +
" "
);
Console.WriteLine();
}
}
}
}
Implementation Of Linked Lists
Collections Name Space
C#