-
Notifications
You must be signed in to change notification settings - Fork 0
/
UnOrderedList.cs
85 lines (78 loc) · 2.86 KB
/
UnOrderedList.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
//-----------------------------------------------------------------------
// <copyright file="UnOrderedList.cs" company="Bridgelabz">
// Company copyright tag.
// </copyright>
//-----------------------------------------------------------------------
namespace DataStrucure
{
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
/// <summary>
/// the class name should be unoderedlist
/// </summary>
public class UnOrderedList
{
/// <summary>
/// the add and moving the file
/// </summary>
public void AddAndRemoveFile()
{
//// creating the utility object class
Utility utility = new Utility();
//// creating the linked list object
LinkedListClass ll1 = new LinkedListClass();
LinkedList<string> ll = new LinkedList<string>();
//// creating one file path object
string text = File.ReadAllText(utility.FileForUnoderedList());
//// spliting the text in spaces
string[] word = text.Split(new char[] { ' ' });
Console.WriteLine("LINKED LIST FILE");
foreach (string list in word)
{
ll1.AddFirst(list);
}
ll1.Print();
foreach (string list in ll)
{
Console.WriteLine(list);
}
//// check the length of character in text file
Console.WriteLine("THE LENGTH CHARATER IN FILE " + text.Length);
Console.WriteLine("Enetr the String To the Search in file");
string search = Console.ReadLine();
if (Regex.IsMatch(search.Replace(" ", string.Empty), @"^[a-zA-Z]+$"))
{
//// searching the element in present in the file
if (ll.Contains(search))
{
Console.WriteLine("seaching the word contain in file and remove from file");
ll.Remove(search);
}
else
{
Console.WriteLine("contain word is not Seaching From File and added in the list");
ll.AddLast(search.Replace(" ", string.Empty));
}
}
else
{
Console.WriteLine("FILE ONLY CHARATER AND LETTER ACCEPERD");
}
foreach (string list in ll)
{
Console.WriteLine(list);
}
string resultStr = string.Join(" ", ll);
using (StreamWriter streamWriter = new StreamWriter(utility.ResultForUnderedlist()))
{
streamWriter.WriteLine(resultStr + " ");
}
Console.ReadLine();
}
}
}