using System;

namespace Practica5Tema3
{
    public class Practica5Tema3
    {
        public static void Main(string[] args)
        {
            // Arreglo definido por usuario
            Console.Write("cuantos elementos quieres acomodar? : ");
            int cantidad = int.Parse(Console.ReadLine());
            int[] arreglo = new int[cantidad];

            // Desde teclado
            for (int i = 0; i < cantidad; i++)
            {
                Console.Write("Ingresame elemento # " + (i + 1) + " :  ");
                arreglo[i] = int.Parse(Console.ReadLine());
            }

            // Arreglo ingresado
            Console.WriteLine("\n Arreglo creado: [" + string.Join(", ", arreglo) + "]");

            // Usar oleaje
            WaveSort.waveSortT(arreglo);

            // Arreglo de onda
            Console.WriteLine("Arreglo en forma de Olitas (Wave Sort): [" + string.Join(", ", arreglo) + "]");
        }
    }

    // Hacer Wave Sort como Linkedlist de Java
    public class WaveSort
    {
        // Método Wave Sort para arreglo
        public static void waveSortT(int[] arr)
        {
            int tamaño = arr.Length;

            for (int i = 1; i < tamaño; i++)
            {
                // En índices pares: arr[i] >= arr[i-1]
                if (i % 2 == 0 && arr[i] < arr[i - 1])
                {
                    int temporal = arr[i];
                    arr[i] = arr[i - 1];
                    arr[i - 1] = temporal;
                }
                // En índices impares: arr[i] <= arr[i-1]
                if (i % 2 != 0 && arr[i] > arr[i - 1])
                {
                    int temporal = arr[i];
                    arr[i] = arr[i - 1];
                    arr[i - 1] = temporal;
                }
            }
        }
    }
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: