-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
208 lines (166 loc) · 7.17 KB
/
Program.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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
using DSA;
internal class Program
{
public static DoublyLinkedList list = new DoublyLinkedList();
private static void ContinueTest()
{
Console.WriteLine("Press any key to continue...");
Console.ReadKey();
}
private static void Main(string[] args)
{
Console.Clear();
Console.WriteLine("This is Singly Linked List Implementation\n");
Console.WriteLine("Press any key to continue...");
Console.ReadKey();
Console.Clear();
int choice;
string[] MenuItems = { "Append Data", "Prepend Data", "Insert Data", "Display Data", "Update Data", "Delete Element", "Rotate Forward", "Rotate Backward", "Exit" };
int data;
do
{
Console.WriteLine("Menu : ");
Console.WriteLine("----------------------------------");
for (int i = 0; i < MenuItems.Length; ++i)
{
Console.WriteLine($"{i + 1} {MenuItems[i]}");
}
Console.Write("Enter Your Choice : ");
int.TryParse(Console.ReadLine(), out choice);
switch (choice)
{
case 1:
Console.Clear();
Console.WriteLine($"---[{MenuItems[0]}]---");
Console.Write("Enter Data : ");
int.TryParse(Console.ReadLine(), out data);
list.AppendList(data);
Console.Clear();
break;
case 2:
Console.Clear();
Console.WriteLine($"---[{MenuItems[1]}]---");
Console.Write("Enter New Head Data : ");
int.TryParse(Console.ReadLine(), out data);
list.PrependList(data);
Console.Clear();
break;
case 3:
Console.Clear();
Console.WriteLine($"---[{MenuItems[2]}]---");
Console.Write("Enter Data : ");
int.TryParse(Console.ReadLine(), out data);
Console.Write("Enter Position Where To Insert : ");
int.TryParse(Console.ReadLine(), out choice);
list.InsertInList(data, choice);
Console.WriteLine("Press any key to continue...");
Console.ReadKey();
Console.Clear();
break;
case 4:
Console.Clear();
Console.WriteLine($"---[{MenuItems[3]}]---");
list.DisplayList();
Console.WriteLine("Press any key to continue...");
Console.ReadKey();
Console.Clear();
break;
case 5:
Console.Clear();
Console.WriteLine($"---[{MenuItems[4]}]---");
Console.Write("Enter Position To Update : ");
int.TryParse(Console.ReadLine(), out data);
Console.WriteLine("Enter The New Data : ");
int.TryParse(Console.ReadLine(), out choice);
list.UpdateNode(choice, data);
Console.WriteLine("Press any key to continue...");
Console.ReadKey();
Console.Clear();
break;
case 6:
Console.Clear();
Console.WriteLine($"---[{MenuItems[5]}]---");
Console.Write("Enter Position Where To Delete : ");
int.TryParse(Console.ReadLine(), out data);
list.DeletListNode(data);
Console.WriteLine("Press any key to continue...");
Console.ReadKey();
Console.Clear();
break;
case 7:
Console.Clear();
Console.WriteLine($"---[{MenuItems[6]}]---");
Console.Write("Enter Number Of Position To Rotate By : ");
int.TryParse(Console.ReadLine(), out data);
list.RotateForward(data);
Console.WriteLine("Press any key to continue...");
Console.ReadKey();
Console.Clear();
break;
case 8:
Console.Clear();
Console.WriteLine($"---[{MenuItems[7]}]---");
Console.Write("Enter Number Of Position To Rotate By : ");
int.TryParse(Console.ReadLine(), out data);
list.RotateBackward(data);
Console.WriteLine("Press any key to continue...");
Console.ReadKey();
Console.Clear();
break;
case 9:
Console.Clear();
Console.WriteLine("Application Exited...");
Console.WriteLine("Press any key to continue...");
Console.ReadKey();
Console.Clear();
break;
case 79: //It is hidden and only used for testing purpose. You can write your custom tests here. Take help ContinueTest() method see cler and neat output on console.
Console.Clear();
Console.WriteLine("Running Tests.....");
int test = 10;
while (test > 0)
{
list.AppendList(45);
list.AppendList(46);
list.AppendList(47);
list.DisplayList();
ContinueTest();
list.RotateBackward(1);
list.DisplayList();
ContinueTest();
list.RotateBackward(1);
list.DisplayList();
ContinueTest();
list.RotateBackward(1);
list.DisplayList();
ContinueTest();
list.RotateBackward(1);
list.DisplayList();
ContinueTest();
list.RotateForward(1);
list.DisplayList();
ContinueTest();
list.RotateForward(1);
list.DisplayList();
ContinueTest();
list.RotateForward(1);
list.DisplayList();
ContinueTest();
list.RotateForward(1);
list.DisplayList();
ContinueTest();
test = 0;
}
Console.Clear();
break;
default:
Console.Clear();
Console.WriteLine("Please Enter Valid Choice");
Console.WriteLine("Press any key to continue...");
Console.ReadKey();
Console.Clear();
break;
}
} while (choice != 9);
}
}