Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Min max elements swap of the array
//Rextester.Program.Main is the entry point for your code. Don't change it. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Rextester { public class Program { public static void Main(string[] args) { int [] arr = { 1, 2, 3, 4, 5, 6 }; Console.Write("The array is : " ) ; Display(arr); MinMaxSwap(arr); Console.Write("After min max swap : " ) ; Display(arr); } public static void MinMaxSwap(int[] input) { if (input.Length == 0) return; int maxIndx = 0; int minIndx = 0; for (int i = 1; i < input.Length; i++) { if (input[maxIndx] > input[i]) maxIndx = i; if (input[minIndx] < input[i]) minIndx = i; } int valMax = input[maxIndx]; input[maxIndx] = input[minIndx]; input[minIndx] = valMax; } public static void Display(int []arr) { int n = arr.Length; for (int i = 0; i < n; ++i) Console.Write(arr[i] + " "); Console.WriteLine(); } } }
run
|
edit
|
history
|
help
0
Added Carnival, List Matching
Hi
Sorting Square Problem
TrzyKreski
csharp enum
QuickSort
learning1
OOP vs DOD 2
Generics Base class constraints
Merge Sort