-
Notifications
You must be signed in to change notification settings - Fork 0
/
Bead.cs
194 lines (184 loc) · 5.82 KB
/
Bead.cs
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
using System;
namespace Bead
{
class Bead
{
private char size;
private string color;
private Bead next;
public Bead(char size, string color)
{
this.size = size;
this.color = color;
this.next = null;
}
public Bead(char size, string color, Bead bead)
{
this.size = size;
this.color = color;
this.next = bead;
}
public Bead(char size)
{
this.size = size;
this.next = null;
}
public Bead(char size, Bead bead)
{
this.size = size;
this.next = bead;
}
public Bead(Bead bead)
{
this.size = bead.GetSize();
this.color = bead.GetColor();
this.next = bead.GetNextBead();
}
public char GetSize()
{
return this.size;
}
public string GetColor()
{
return this.color;
}
public Bead GetNextBead()
{
return this.next;
}
public void SetSize(char ch)
{
this.size = ch;
}
public void SetColor(string color)
{
this.color = color;
}
public void SetNextBead(Bead bead)
{
this.next = bead;
}
public override string ToString()
{
string st = "";
return st = "Size: " + this.size +"\n"+this.next /*" Color: " + this.color*/;
}
class IntNode
{
private int info;
private IntNode next;
public IntNode(int info)
{
this.info = info;
this.next = null;
}
public IntNode(int info, IntNode a)
{
this.info = info;
this.next = a;
}
public int GetInfo()
{
return this.info;
}
public IntNode GetNext()
{
return this.next;
}
public void SetInfo(int info)
{
this.info = info;
}
public void SetNext(IntNode a)
{
this.next = a;
}
public static IntNode AddNode(IntNode pos, int a)//function for add a organ in to the list
{
IntNode c = new IntNode(a, pos.GetNext());
pos.SetNext(c);
return pos;
}
public static IntNode DelNode(IntNode pos)// function for delete a organ in the list
{
IntNode a = pos.GetNext();
pos.SetNext(pos.GetNext().GetNext());
a.SetNext(null);
return a;
}
public static int LenNode(IntNode allList)// this function return the length node
{
int count = 0;
while (allList.GetNext() != null)
{
allList = allList.GetNext();
count++;
}
return count;
}
public static int LenNodeR(IntNode allList)// this Recursive function return the length node
{
if (allList.GetNext() == null)
return 0;
else
{
allList = allList.GetNext();
return 1+LenNodeR(allList);
}
}
public static void AddNodeA(IntNode a, int x)
{
bool flag = true;
while (a.GetNext() != null)
{
if (x > a.GetInfo() && x <= a.GetNext().GetInfo())
{
IntNode c = new IntNode(x, a.GetNext());
a.SetNext(c);
a = c;
flag = false;
}
else if (x <= a.GetInfo() && flag)
{
IntNode c = new IntNode(a.GetInfo(), a.GetNext());
a.SetInfo(x);
a.SetNext(c);
flag = false;
}
a = a.GetNext();
}
if (x > a.GetInfo() && flag)
{
IntNode p = new IntNode(x);
a.SetNext(p);
}
}
public override string ToString()
{
string st = "";
return st = "Info :" + this.info + "\n" + this.next;
}
static void Main(string[] args)
{
Bead a1 = new Bead('L');//create list
Bead b = new Bead('M', a1);
Bead c = new Bead('S', b);
Bead d = new Bead('M', c);
Bead e = new Bead('M', d);
Bead e2 = new Bead('M',e);
Console.WriteLine(e2);
/*Bead add = new Bead(new Bead('S', "blue", new Bead('M', "green", new Bead('L', "yellow"))));
IntNode a = new IntNode(2, new IntNode(3, new IntNode(5)));
AddNodeA(a,5);
Console.WriteLine(a);
a= AddNode(a, 4);
Console.WriteLine(LenNodeR(a));
Console.WriteLine(a);
IntNode p = DelNode(a);
Console.WriteLine(p);
Console.WriteLine(a);
Console.WriteLine(LenNode(p));*/
}
}
}
}