Question: I WILL BE SURE TO UPVOTE!!!! :) Please do this in C# and modify and add below as needed so that it can run in

I WILL BE SURE TO UPVOTE!!!! :)

Please do this in C# and modify and add below as needed so that it can run in Visual Studio Code 2022! Create a doubly linked list that is generic without the use of C# library functions and add to the code below (and test them with both int and string):

-Delete(given a value)

-Delete(given a node)

-Reverse

-Print

*NOTE*:Please also be sure to add a ToString override in the node class.

CODE TO MODIFY:

namespace Program { public class Node { public T Value { get; set; } public Node? Prev { get; set; } public Node? Next { get; set; }

public Node(T value) { Value = value; Prev = null; Next = null; } } public class DoublyLinkedList { //data Node? head; Node? tail;

//methods //Add, same as AddLast public void Add(T someValue) //O(1) { AddLast(someValue);//O(1) }

public void AddLast(T someValue)//O(1) { //create a new node Node newNode = new Node(someValue);

if (IsEmpty()) { head = newNode; tail = newNode; } else { //link in the new node newNode.Prev = tail; tail.Next = newNode; //update tail tail = newNode; } }

//AddFirst public void AddFirst(T someValue) //O(1) { //create a new node Node newNode = new Node(someValue);

if (IsEmpty()) { head = newNode; tail = newNode; } else { //point newNode to the head newNode.Next = head; //point head to newNode head.Prev = newNode; //update head head = newNode; } } //IsEmpty private bool IsEmpty() { return head == null; } //Clear public void Clear() { head = null; }

//DeleteFirst public void DeleteFirst() //O(1) { if (head == null) { throw new Exception("You cannot delete from an empty list"); } else if (head == tail) //you have only one element in the list { head = null; tail = null; } else { //move the head head = head.Next; head.Prev = null; } }

//DeleteLast public void DeleteLast()//O(1) { if (tail == null) { throw new Exception("You cannot delete from an empty list"); } else if (head == tail) //you have only one element in the list { head = null; tail = null; } else { //traverse the list ... go to the second to last node tail = tail.Prev; tail.Next = null; } }

//DeleteValue public void DeleteValue(T someValue) { if (head == null) { throw new Exception("You cannot delete from an empty list"); } else if (someValue.Equals(head.Value)) { DeleteFirst(); } else if (someValue.Equals(tail.Value)) { DeleteLast(); } else { Node finger = head.Next; while (finger != null && !finger.Value.Equals(someValue)) { finger = finger.Next; }

if (finger != null) // we found the value { finger.Prev.Next = finger.Next; }

} } } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!