Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

You are working on a project that requires the use of a linked list data structure in C#. You have been tasked with implementing a

You are working on a project that requires the use of a linked list data structure in C#. You have been tasked with implementing a basic linked list class that can add and remove nodes, and retrieve the value of a node at a given index.

Task 1: Linked List Implementation

Your first task is to implement the LinkedList class. The LinkedList class should have the following properties and methods:

Properties:

  • Count: The number of nodes in the list.
  • Head: The first node in the list.

Methods:

  • AddFirst(string value): Adds a new node with the given value to the beginning of the list.
  • AddLast(string value): Adds a new node with the given value to the end of the list.
  • RemoveFirst(): Removes the first node in the list.
  • RemoveLast(): Removes the last node in the list.
  • GetValue(int index): Retrieves the value of the node at the given index.

Task 2: Testing

Your second task is to write unit tests to test the functionality of the LinkedList class. The tests should include:

  1. Adding nodes to the beginning of the list
  2. Adding nodes to the end of the list
  3. Removing the first node in the list
  4. Removing the last node in the list
  5. Retrieving the value of a node at a given index
  6. Determining the size of the list

Make test project that includes these tests and ensures that the LinkedList class works correctly. Test for edge cases, such as retrieving and removing from an empty linked list.

Use the following list of names to populate the linked list:

  • Joe Blow
  • Joe Schmoe
  • John Smith
  • Jane Doe
  • Bob Bobberson
  • Sam Sammerson
  • Dave Daverson

There should be 3 Class:

LinkedList.cs

Node.cs

UnitTest1.cs

Here is some code to work with:

In LinkedList.cs:

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;

namespace LinkedListLabD { internal class LinkedList { public Node Head { get; set; } public int Count { get; set; }

public LinkedList() { this.Head = null; }

public void AddFirst(string value) { // Create new node

// Assign value to new node

// Create variable (old head node) and assign it node to head

// Assign head to new node

// Assign next to old head node

// Increment Count } } }

In Node.cs:

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;

namespace LinkedListLabD { internal class Node { public string Value { get; set; } public Node Next { get; set; }

} }

In UnitTest1.cs:

namespace LinkedListLabD { public class Tests { private LinkedList sll;

[SetUp] public void Setup() { sll = new LinkedList(); }

[Test] public void TestPrepend() { //Assert.Pass(); sll.AddFirst("Joe Blow");

// Assert that the Count is 1

// Assert list has "Joe Blow" }

[Test] public void TestPrependFail() {

}

[TearDown] public void TearDown() { sll.Head = null; sll.Count = 0; } } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Mobile Communications

Authors: Jochen Schiller

2nd edition

978-0321123817, 321123816, 978-8131724262

More Books

Students also viewed these Programming questions

Question

Why is the convolutional layer more critical for deep learning?

Answered: 1 week ago