public static CLL <int> TakeInputList_CLL(bool isRandom = true, int MinContentLegth = 10, int MaxContentLength = 20, int MaxValue = 20) { if (!isRandom) { CLL <int> meList = new CLL <int>(); Console.WriteLine("Enter the number of elements in List"); int numbers = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Enter elements of List\n "); int i = 1; while (i <= numbers) { meList.Insert(Convert.ToInt32(Console.ReadLine()), false); i++; } return(meList); } else { InputGenerator ioGenerator = new InputGenerator(); ioGenerator.MaxContentLength = MaxContentLength; ioGenerator.MinContentLength = MinContentLegth; var meList = InputStream.ReadFileAsCLL(ioGenerator.GenerateIntegerInputFile(MaxValue)); return(meList); } }
public static CLL <int> ReadFileAsCLL(string filePath) { if (!File.Exists(filePath)) { return(null); } CLL <int> list = new CLL <int>(); using (FileStream inputStream = File.Open(filePath, FileMode.Open, FileAccess.Read)) { byte[] inputArray = new byte[inputStream.Length]; inputStream.Read(inputArray, 0, inputArray.Length); string inputvalues = ASCIIEncoding.ASCII.GetString(inputArray); string[] values = inputvalues.Split(','); foreach (var value in values ?? Enumerable.Empty <string>()) { int number; if (int.TryParse(value, out number)) { list.Insert(number, false); } } } return(list); }