Question
(I WILL BE SURE TO UPVOTE)!!!!!!!!!!! :) Please create a doubly linked list that is generic in C# and modify the code below as needed
(I WILL BE SURE TO UPVOTE)!!!!!!!!!!! :)
Please create a doubly linked list that is generic in C# and modify the code below as needed so that it will run in visual studio 2022. You MUST use the code below for SinglyLinkedList as a starting point, and change that as needed for your DoublyLinkedList. You are expected to fully implement this class, without the use of the C# library functions (from namespaces such as System.Collections and System.Collections.Generic). Make sure it includes the following methods (and test them with both int and string):
AddFirst
AddLast
DeleteFirst
DeleteLast
Delete(given a value)
Delete(given a node)
Reverse
IsEmpty
Clear
CODE TO MODIFY:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;
namespace CSC340._515_SinglyLinkedList { public class SinglyLinkedList
//methods //Add, same as AddBack public void Add(T someValue) //O(n) { AddBack(someValue);//O(n) }
public void AddBack(T someValue)//O(n) { //create a new node Node
if (IsEmpty()) { head = newNode; } else { //find the last node: Node
//when you get here, finger points to the last node finger.Next = newNode;//link in the new node }
} //AddFirst public void AddFirst(T someValue) //O(1) { //create a new node Node
//point newNode to the head newNode.Next = head;
//move the head head = newNode; } //DeleteFirst public void DeleteFirst() //O(1) { if(head==null) { throw new Exception("You cannot delete from an empty list"); } else { //move the head head = head.Next; } }
//DeleteLast public void DeleteLast()//O(n) { if(head==null) { throw new Exception("You cannot delete from an empty list"); } else if(head.Next == null) //you have only one element in the list { head = null; } else { //traverse the list ... go to the next to last node Node
while (finger.Next.Next != null) { finger = finger.Next; }
//link the last node out finger.Next = null; } }
//DeleteValue public void DeleteValue(T someValue) { if (someValue.Equals(head.Value)) DeleteFirst(); else { Node
if(finger.Next != null) // we found the value { finger.Next = finger.Next.Next; } } }
//SearchValue public Node
//you get here if someValue was not found return null; }
//ToString public override string ToString() { String result = "";
Node
return result; }
//Clear public void Clear() { head = null; }
//IsEmpty public bool IsEmpty() { return head == null; }
//ctors public SinglyLinkedList() { //head = null; } } }
I will be sure to upvote. thank you!
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started