static void Main() { CircleS[] circArr = new CircleS[] { new CircleS(1, 1, 3), new CircleS(2, 3, 4), new CircleS(-1, -2, 3), new CircleS(4, 3, 1) }; Console.WriteLine("Ключи и круги до сортировки:"); // Массив ключей для сортировки по уменьшению удаленности // кругов от начала координат: PointS[] keys = new PointS[circArr.Length]; PointS p0 = new PointS(0, 0); for (int i = 0; i < circArr.Length; i++) { keys[i] = circArr[i].Center; Console.Write("distance[{0}]={1:g3}\t", i, keys[i].distance(p0)); Console.WriteLine(circArr[i].ToString()); } Array.Sort(keys, circArr); Console.WriteLine("Массив кругов после сортировки: "); foreach (CircleS cs in circArr) { Console.WriteLine(cs.ToString()); } Console.WriteLine("Для выхода из программы нажмите ENTER."); Console.ReadLine(); }
static void Main(string[] args) { Random rnd = new Random(); CircleS[] arr = new CircleS[10]; for (int i = 0; i < arr.Length; ++i) { arr[i] = new CircleS(rnd.Next(1, 10), rnd.Next(1, 10), rnd.Next(1, 10)); } arr.ToList().ForEach(el => Console.WriteLine(el)); Console.WriteLine(); arr.OrderBy(el => el.Radius).ToList().ForEach(el => Console.WriteLine(el)); Console.WriteLine(); arr.OrderBy(el => el.Center).ToList().ForEach(el => Console.WriteLine(el)); }
static void Main(string[] args) { var circleSes = new CircleS[rnd.Next(5, 10)]; Console.WriteLine("Before:"); Console.WriteLine(); for (var i = 0; i < circleSes.Length; i++) { circleSes[i] = new CircleS(rnd.NextDouble() * rnd.Next(5, 10), rnd.NextDouble() * rnd.Next(5, 10), rnd.NextDouble() * rnd.Next(5, 10)); Console.WriteLine(circleSes[i]); } Array.Sort(circleSes); Console.WriteLine(); Console.WriteLine("After:"); foreach (var circle in circleSes) { Console.WriteLine(circle); } }
/// <summary> /// Get array of circles. /// </summary> /// <returns> Array of circles </returns> private static CircleS[] GetCircles() { var circles = new CircleS[Amount]; for (var i = 0; i < Amount; i++) { // Attempt to create new circle. try { var x = GetDoubleFromInterval(); var y = GetDoubleFromInterval(); var radius = GetDoubleFromInterval(); circles[i] = new CircleS(x, y, radius); } catch (ArgumentOutOfRangeException ex) { // Print error message. PrintMessage(ex.Message + Environment.NewLine, ConsoleColor.Red); i--; } } return(circles); }
static void Main(string[] args) { int n = 10; CircleS[] circleS = new CircleS[n]; for (int i = 0; i < circleS.Length; i++) { circleS[i] = new CircleS(random.NextDouble() + random.Next(-10, 10), random.NextDouble() + random.Next(-10, 10), random.NextDouble() + random.Next(0, 10)); Console.WriteLine(circleS[i].ToString()); } Console.WriteLine(); Array.Sort(circleS); foreach (CircleS a in circleS) { Console.WriteLine(a.ToString()); } PointS center = new PointS(0, 0); Console.WriteLine(); Array.Sort(circleS, (CircleS a, CircleS b) => { if (a.Center.distance(center) > b.Center.distance(center)) { return(1); } if (a.Center.distance(center) < b.Center.distance(center)) { return(-1); } return(0); } ); foreach (CircleS a in circleS) { Console.WriteLine(a.ToString()); } Array.Sort(circleS); Console.WriteLine(); double[] keys = new double[n]; for (int i = 0; i < keys.Length; i++) { keys[i] = circleS[i].Center.distance(center); } Array.Sort(keys, circleS); foreach (CircleS a in circleS) { Console.WriteLine(a.ToString() + " " + a.Center.distance(center)); } Console.ReadKey(); }