1. Write a menu-driven program to perform the following operations in a single linked list by using suitable user-defined functions for each case.
a) Traversal of the list.
b) Check if the list is empty.
c) Insert a node at a certain position (at beginning/end/any position).
d) Delete a node at a certain position (at beginning/end/any position).
e) Delete a node for the given key.
f) Count the total number of nodes.
g) Search for an element in the linked list.
Verify & validate each function from main method.
2. WAP to display the contents of a linked list in reverse order
using System;
using System.Collections.Generic;
class Main1 {
static public void Main()
{
LinkedList<String> list = new LinkedList<String>();
list.AddLast("A");
list.AddLast("B");
list.AddLast("C");
list.AddLast("D");
list.AddLast("E");
list.AddLast("F");
foreach(string str in list)
{
Console.WriteLine(str);
}
list.Remove(list.First);
foreach(string str in list)
{
Console.WriteLine(str);
}
list.Remove("D");
foreach(string str in list)
{
Console.WriteLine(str);
}
list.RemoveFirst();
foreach(string str in list)
{
Console.WriteLine(str);
}
list.RemoveLast();
foreach(string str in list)
{
Console.WriteLine(str);
}
Console.WriteLine("Numbers: {0}",
list.Count);
}
}
Comments
Leave a comment