Answer to Question #233804 in C# for prince kumar

Question #233804

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





1
Expert's answer
2021-09-06T23:57:33-0400
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);
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS