using System using System Collections Generic namespace CourseWork pub

 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
using System;
using System.Collections.Generic;
namespace CourseWork
{
public class LinkedList
{
private Node head;
private int count;
public LinkedList()
{
this.head = null;
this.count = 0;
}
public bool Empty
{
get { return this.count == 0; }
}
public int Count
{
get { return this.count; }
}
public int Add(int index, int obj)
{
if (index < 0)
throw new ArgumentOutOfRangeException("Index: " + index);
if (index > count)
index = count;
Node current = this.head;
if (this.Empty || index == 0)
{
this.head = new Node(obj, this.head);
}
else
{
for (int i = 0; i < index - 1; i++)
current = current.Next;
current.Next = new Node(obj, current.Next);
}
count++;
return obj;
}
public int Add(int obj)
{
return this.Add(count, obj);
}
public void Print()
{
Console.Write(head.Data + " -> ");
if (head.Next != null)
{
head = head.Next;
Print();
}
}
public void Sort()
{
//Node current = this.head;
if(head.Data > head.Next.Data)
{
Node temp = this.head;
temp.Next = head.Next;
}
}
}
}