Question

In C# create a linked list with numbers 22, 34, 56, 99, 101. Insert the number...

In C# create a linked list with numbers 22, 34, 56, 99, 101. Insert the number 15 in between 34 and 56.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Following is the code which first adds all these numbers to the linked list .Then, it removes elements from first and inserts 15 in its desired place.

using System;
using System.Collections.Generic;
class code {
static public void Main()
{
LinkedList<String> MyList = new LinkedList<String>();
MyList.AddLast("22");
MyList.AddLast("34");
MyList.AddLast("56");
MyList.AddLast("99");
MyList.AddLast("101");
Console.WriteLine("Initial List :");
foreach(string st in MyList)
{
Console.WriteLine(st);
}
  
MyList.Remove(MyList.First);
MyList.Remove(MyList.First);
MyList.AddFirst("15");
MyList.AddFirst("34");
MyList.AddFirst("22");
Console.WriteLine("Final List :");
foreach(string st in MyList)
{
Console.WriteLine(st);
}
  
}
}

Add a comment
Know the answer?
Add Answer to:
In C# create a linked list with numbers 22, 34, 56, 99, 101. Insert the number...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT