Solved: Write a program that stores list of product names…

$30.00

Category:

Description

Solved: Write a program that stores list of product names…

Write a program that stores the list of product names in a linked list. The user will enter a product name and the program needs to check if the linked list contains the given product.

This is what I have so far…

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

namespace LinkedList

{

public class Node

{

public Node Next;

public object Value;

}

public class LinkedList

{

private Node head;

private Node current;

public int Count;

public void PrintAllNodes()

{

//Traverse from head

Console.Write(“Head ->”);

Node current = head;

while (current.Next != null)

{

current = current.Next;

Console.Write(current.Value);

Console.Write(“->”);

}

Console.Write(“NULL”);

}

public LinkedList()

{

head = new Node();

current = head;

}

public void AddLast(object data)

{

Node newNode = new Node();

newNode.Value = data;

current.Next = newNode;

current = newNode;

Count++;

}

class Program

{

static void Main(string[] args)

{

LinkedList lnklist1 = new LinkedList();

lnklist1.PrintAllNodes();

Console.WriteLine();

lnklist1.AddLast(“Peanut”);

lnklist1.AddLast(“Butter”);

lnklist1.AddLast(“Jelly”);

lnklist1.PrintAllNodes();

Console.WriteLine();

Console.WriteLine(“\nNumber of items: {0}\n”, lnklist1.Count);

LinkedList lnklist2 = new LinkedList();

lnklist2.PrintAllNodes();

Console.WriteLine();

lnklist2.AddLast(“Bacon”);

lnklist2.AddLast(“Lettuce”);

lnklist2.AddLast(“Tomato”);

lnklist2.PrintAllNodes();

Console.WriteLine();

 

Console.WriteLine(“\nNumber of items: {0}”, lnklist2.Count);

Console.WriteLine(“\nEnter a product: “);

string input = Console.ReadLine();

lnklist1.AddLast(input);

while (input != “”)

{

Console.WriteLine(“Please enter another item: “);

input = Console.ReadLine();

}

Console.ReadKey();

}

}

}

}

 


error: Content is protected !!