SlideShare a Scribd company logo
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
*/

More Related Content

PDF
TutorialII_Updated____niceupdateprogram.pdf
PDF
Exception to indicate that Singly LinkedList is empty. .pdf
DOCX
C++ please put everthing after you answer it- thanks Complete the stub.docx
PDF
hi i have to write a java program involving link lists. i have a pro.pdf
PDF
Write a program to implement below operations with both singly and d.pdf
PPTX
Data Structures and Agorithm: DS 04 Linked List.pptx
DOCX
Write a program that creates a LinkedList object of 10 characters- the.docx
PDF
C++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdf
TutorialII_Updated____niceupdateprogram.pdf
Exception to indicate that Singly LinkedList is empty. .pdf
C++ please put everthing after you answer it- thanks Complete the stub.docx
hi i have to write a java program involving link lists. i have a pro.pdf
Write a program to implement below operations with both singly and d.pdf
Data Structures and Agorithm: DS 04 Linked List.pptx
Write a program that creates a LinkedList object of 10 characters- the.docx
C++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdf

Similar to C# code pleaseWrite a program that creates a link list object of 1.pdf (20)

PDF
fix the error - class Node{ int data- Node next-.pdf
PDF
Using the provided table interface table.h and the sample linked lis.pdf
PPTX
Data Structures and Agorithm: DS 05 Doubly Linked List.pptx
PDF
Java AssignmentUsing the ListNode.java file below Write method.pdf
PDF
Sorted number list implementation with linked listsStep 1 Inspec.pdf
PPT
MO 2020 DS Applications of Linked List 1 AB.ppt
PDF
Create a C program which auto-completes suggestions when beginning t.pdf
PDF
Linked List, Types of Linked LIst, Various Operations, Applications of Linked...
PDF
You can list anything, it doesnt matter. I just want to see code f.pdf
PPT
Data structures cs301 power point slides lecture 03
PDF
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
PDF
could you implement this function please, im having issues with it..pdf
PPT
Ch17
PDF
Write an algorithm that reads a list of integers from the keyboard, .pdf
PDF
Note             Given Code modified as required and required met.pdf
PDF
Lab-2.4 101.pdf
PDF
Using visual studio 2022- a C# windows form application- and your Doub.pdf
PDF
THE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdf
PPTX
Chapter 4 Linked List introduction lessons.pptx
PDF
Database By Salman Mushtaq
fix the error - class Node{ int data- Node next-.pdf
Using the provided table interface table.h and the sample linked lis.pdf
Data Structures and Agorithm: DS 05 Doubly Linked List.pptx
Java AssignmentUsing the ListNode.java file below Write method.pdf
Sorted number list implementation with linked listsStep 1 Inspec.pdf
MO 2020 DS Applications of Linked List 1 AB.ppt
Create a C program which auto-completes suggestions when beginning t.pdf
Linked List, Types of Linked LIst, Various Operations, Applications of Linked...
You can list anything, it doesnt matter. I just want to see code f.pdf
Data structures cs301 power point slides lecture 03
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
could you implement this function please, im having issues with it..pdf
Ch17
Write an algorithm that reads a list of integers from the keyboard, .pdf
Note             Given Code modified as required and required met.pdf
Lab-2.4 101.pdf
Using visual studio 2022- a C# windows form application- and your Doub.pdf
THE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdf
Chapter 4 Linked List introduction lessons.pptx
Database By Salman Mushtaq
Ad

More from duttakajal70 (20)

PDF
Explain the relevance of the rules against hearsay to digital eviden.pdf
PDF
Electric and magnetic fields in an electromagnetic wave are alway.pdf
PDF
During our laboratory exercise on cellular the Krebs cycle in.pdf
PDF
25. On January 3, Pippin Corporation purchased 1,900 shares of the c.pdf
PDF
Define filtration and active transport.SolutionFiltration is t.pdf
PDF
Why wouldnt you want to post a payment against an invoice directly.pdf
PDF
Cisco routers and switches use two configuration files. Where is the.pdf
PDF
Which of the following is a simple compressible system A mixtur.pdf
PDF
Which of the following statements is (are) trueI Walls Street i.pdf
PDF
What would be the most effective method of reducing the incidence of .pdf
PDF
What is a micelle What is a vesicle How are these structures the s.pdf
PDF
To determine her breathing rate, Miranda divides up her day into thre.pdf
PDF
On January 29th, 2014, the Royal Caribbean cruise ship Explorer of.pdf
PDF
Name and describe the six main types of lymphatic cells, discuss the.pdf
PDF
Let X1, X2, . . . , Xn be n independent continuous random variables,.pdf
PDF
Java Program using RecursionWrite a program that reads in a file .pdf
PDF
In major league baseball, there are 5 teams in the Eastern division .pdf
PDF
Im off by a minus sign, can you find my error In a previous probl.pdf
PDF
If the characteristic followed in the pedigree is X-linked recessiv.pdf
PDF
create a Tic Tac Toe game using JSP Scripting elements and a JSP pag.pdf
Explain the relevance of the rules against hearsay to digital eviden.pdf
Electric and magnetic fields in an electromagnetic wave are alway.pdf
During our laboratory exercise on cellular the Krebs cycle in.pdf
25. On January 3, Pippin Corporation purchased 1,900 shares of the c.pdf
Define filtration and active transport.SolutionFiltration is t.pdf
Why wouldnt you want to post a payment against an invoice directly.pdf
Cisco routers and switches use two configuration files. Where is the.pdf
Which of the following is a simple compressible system A mixtur.pdf
Which of the following statements is (are) trueI Walls Street i.pdf
What would be the most effective method of reducing the incidence of .pdf
What is a micelle What is a vesicle How are these structures the s.pdf
To determine her breathing rate, Miranda divides up her day into thre.pdf
On January 29th, 2014, the Royal Caribbean cruise ship Explorer of.pdf
Name and describe the six main types of lymphatic cells, discuss the.pdf
Let X1, X2, . . . , Xn be n independent continuous random variables,.pdf
Java Program using RecursionWrite a program that reads in a file .pdf
In major league baseball, there are 5 teams in the Eastern division .pdf
Im off by a minus sign, can you find my error In a previous probl.pdf
If the characteristic followed in the pedigree is X-linked recessiv.pdf
create a Tic Tac Toe game using JSP Scripting elements and a JSP pag.pdf
Ad

Recently uploaded (20)

PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
PDF
RMMM.pdf make it easy to upload and study
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PPTX
Presentation on HIE in infants and its manifestations
PDF
01-Introduction-to-Information-Management.pdf
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
Anesthesia in Laparoscopic Surgery in India
PDF
Complications of Minimal Access Surgery at WLH
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
Chinmaya Tiranga quiz Grand Finale.pdf
PDF
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
PDF
VCE English Exam - Section C Student Revision Booklet
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
RMMM.pdf make it easy to upload and study
STATICS OF THE RIGID BODIES Hibbelers.pdf
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
Presentation on HIE in infants and its manifestations
01-Introduction-to-Information-Management.pdf
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Anesthesia in Laparoscopic Surgery in India
Complications of Minimal Access Surgery at WLH
Final Presentation General Medicine 03-08-2024.pptx
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Chinmaya Tiranga quiz Grand Finale.pdf
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
VCE English Exam - Section C Student Revision Booklet
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student

C# code pleaseWrite a program that creates a link list object of 1.pdf

  • 1. 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;
  • 2. 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) {
  • 3. 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 */