2. Change List
Къде е грешката? Дава ми, че надвишавам памет? Как да го оправя, колеги?
using System;
using System.Linq;
using System.Collections.Generic;
namespace zad02ChangeList
{
class Program
{
static void Main(string[] args)
{
List<int> numbers = Console.ReadLine()
.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
.Select(int.Parse)
.ToList();
string line = Console.ReadLine();
while (line != "Odd" || line != "Even")
{
string[] command = line
.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
.ToArray();
string manipulator = command[0];
if (manipulator == "Delete")
{
int element = int.Parse(command[1]);
numbers.RemoveAll(x => x == element);
}
else if (manipulator == "Insert")
{
int element = int.Parse(command[1]);
int position = int.Parse(command[2]);
numbers.Insert(position, element);
}
}
if (line == "Odd")
{
numbers.RemoveAll(x => x % 2 == 1);
}
else if (line == "Even")
{
numbers.RemoveAll(x => x % 2 == 0);
}
Console.WriteLine(string.Join(" ", numbers));
}
}
}