C code please Write a program that creates a link list objec

C# code please

Write a program that creates a link list object of 10 characters, then creates a second list object containing a copy of the first list but in reverse order.

Solution

using System;

class LinkedList
{
private char data;
private LinkedList next;

public LinkedList()
{
data = \'c\';
next = null;
}

public LinkedList(char value)
{
data = value;
next = null;
}


public LinkedList Append(char value)
{
LinkedList node = new LinkedList(value);
if(this.next == null)
{
// Easy to handle
node.next = null; // already set in constructor
this.next = node;
}
else
{
// Insert in the middle
LinkedList temp = this.next;
node.next = temp;
this.next = node;
}
return node;
}

public void Display(LinkedList node)
{
if(node == null)
node = this;
System.Console.WriteLine(\"\ \ LinkedList:\ \ \");

while(node != null)
{
System.Console.Write(node.data+\" -> \");
node = node.next;
}
System.Console.Write(\"\ \");
}

public LinkedList Reverse_with_copy(LinkedList head)
{
LinkedList p = head;
LinkedList newhead = null;
while(true)
{
if(p == null)
return newhead;
LinkedList newnode = new LinkedList(p.data);
newnode.next = newhead;
newhead = newnode;
p = p.next;
}
}
}

class Program
{
static void Main(string[] args)
{
LinkedList head = new LinkedList(\'a\');
LinkedList p = head.Append(\'c\');
p = p.Append(\'e\');
p = p.Append(\'h\');
p = p.Append(\'b\');
p = p.Append(\'d\');
p = p.Append(\'f\');
p = p.Append(\'g\');

head.Display(null);
LinkedList newhead = head.Reverse_with_copy(head);   
newhead.Display(null);
}
}

/* sample output

*/

C# code please Write a program that creates a link list object of 10 characters, then creates a second list object containing a copy of the first list but in re
C# code please Write a program that creates a link list object of 10 characters, then creates a second list object containing a copy of the first list but in re

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site