using System namespace CourseWork class LinkedList public Node headNod

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
using System;
namespace CourseWork
{
class LinkedList
{
public Node headNode;
public LinkedList()
{
headNode = null;
}
public void AddToEnd(int data)
{
if (headNode == null)
headNode = new Node(data);
else
headNode.AddToEnd(data);
}
public void SortList()
{
Node node1, node2;
for (node1 = headNode; node1 != null; node1 = node1.next)
for (node2 = headNode; node2 != null; node2 = node2.next)
if(node1.data <= node2.data)
{
int temp = node1.data;
node1.data = node2.data;
node2.data = temp;
}
}
public void Print()
{
if (headNode != null)
headNode.Print();
}
}
}