elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: ¿Eres nuevo? ¿Tienes dudas acerca del funcionamiento de la comunidad? Lee las Reglas Generales


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  Ejercicios
| | | |-+  ejercicio en c#/tipo consola
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: ejercicio en c#/tipo consola  (Leído 7,203 veces)
ronald hisp

Desconectado Desconectado

Mensajes: 33


Las dudas crecen y crecen


Ver Perfil
ejercicio en c#/tipo consola
« en: 7 Diciembre 2007, 17:41 pm »

publico mi tarea de ordenamiento con menu que me tomo un tiempo:::  si lo mejorarian estaria ok.
ojala que les sirva:


********codigo***********

using System;
//using System.Collections.Generic; uso en 2005
using System.Text;

namespace menus_ex
{
    class Program
    {
       
        static void asburbuja(int []le,int t)//burbuja ascendente
        {int temp, nb = 0;
         for (int i = 0; i < t; i++)
         {for (int j = i; j < t; j++)
           {nb++;
            if (le > le[j])
              {temp = le;
               le = le[j];
               le[j] = temp;
              }
            }
          }
        }
        static void desburbuja(int []le,int t)//burbuja descendente
        {int temp, nb = 0;
         for (int i = 0; i < t; i++)
            {for (int j = i; j < t; j++)
             {nb++;
              if (le < le[j])
                {temp = le;
                 le = le[j];
                 le[j] = temp;
                }
              }
           }
        }
        static void selecionas(int []le,int t)//selecion ascendente
        {int menor;
         for (int i = 0; i < t; i++)
           { menor = i;
             for (int j = i + 1; j < t; j++)
             if (le[j] < le[menor])
             menor = j;
             int auxi = le;
             le = le[menor];
             le[menor] = auxi;
           }
        }
        static void seleciondes(int []le,int t)//selecion descendente
        {int menor;
          for (int i = 0; i < t; i++)
           { menor = i;
             for (int j = i + 1; j < t; j++)
             if (le[j] > le[menor])
             menor = j;
             int auxi = le;
             le = le[menor];
             le[menor] = auxi;
           }
        }
        static void insercionas(int []le,int t)//intersecion ascendente
        {int w, ij, auxis;
         bool encontradositio;
         for (w = 1; w < t; w++)
           { auxis = le[w];
             ij = w - 1;
             encontradositio = false;
             while (ij >= 0 && !encontradositio)
             if (le[ij] > auxis)
              { le[ij + 1] = le[ij];
                ij--;
              }
             else
               encontradositio = true;
               le[ij + 1] = auxis;
           }
        }
        static void inserciondes(int []le,int t) //intersecion descendente
        { int w, ij, auxis;
          bool encontradositio;
          for (w = 1; w < t; w++)
            { auxis = le[w];
              ij = w - 1;
              encontradositio = false;
              while (ij >= 0 && !encontradositio)
              if (le[ij] < auxis)
               { le[ij + 1] = le[ij];
                 ij--;
               }
               else
                encontradositio = true;
                le[ij + 1] = auxis;
           }
        }
        static void shell(int []le,int t) //shell ascendente
        { int il, jl, kl, salto;
          salto = t / 2;
          while (salto > 0)
           { for (il = salto; il < t; il++)
              { jl = il - salto;
                while (jl >= 0)
                 { kl = jl + salto;
                   if (le[jl] <= le[kl])
                   jl = -1;
                   else
                    { int auvi = le[jl];
                      le[jl] = le[kl];
                      le[kl] = auvi;
                      jl -= salto;
                     }
                  }
               }
                salto /= 2;
            }
        }
        static void shell1(int []le,int t) //shell descendente
       { int il, jl, kl, salto;
         salto = t / 2;
         while (salto > 0)
          { for (il = salto; il < t; il++)
             {  jl = il - salto;
                while (jl >= 0)
                 {  kl = jl + salto;
                    if (le[jl] >= le[kl])
                    jl = -1;
                    else
                     { int auvi = le[jl];
                       le[jl] = le[kl];
                       le[kl] = auvi;
                       jl -= salto;
                     }

                  }
               }
             salto /= 2;
           }
        }
        public static void quicksort(int[] le, int iz, int de) //quickshort ascendente
        {
            int i = iz;
            int j = de;
            int pivote = le[(iz + de) / 2];
            do
            {
                while (le < pivote)
                {
                    i++;
                }
                while (le[j] > pivote)
                { j--; }
                if (i <= j)
                {
                    int auxi = le;
                    le = le[j];
                    le[j] = auxi;
                    i++;
                    j--;
                }
            } while (i <= j);
            if (j > iz)
                quicksort(le, iz, j);
            if (i < de)
                quicksort(le, i, de);
        }
        public static void quicksort2(int[] le, int iz1, int de1) //quickshort descendente
        {
            int i = iz1;
            int j = de1;
            int pivote = le[(iz1 + de1) / 2];
            do
            {
                while (le > pivote)
                {
                    i++;
                }
                while (le[j] < pivote)
                { j--; }
                if (i <= j)
                {
                    int auxi = le;
                    le = le[j];
                    le[j] = auxi;
                    i++;
                    j--;
                }
            } while (i <= j);
            if (j > iz1)
                quicksort2(le, iz1, j);
            if (i < de1)
                quicksort2(le, i, de1);
        }
        static void recorrer(int[] le,int t)
      {
         for (int i = 0; i < t; i++)
            Console.Write(le + " ");
             Console.WriteLine();
        }
      static void Main(string[] args)
        {   int t;
            Console.WriteLine("--------- MENU ARRAYS---------");
            Console.WriteLine("********llenado******** ");
            Console.WriteLine("ingrese tamaño");
            t = int.Parse(Console.ReadLine());
            int[] le = new int[t];
            for (int i = 0; i < t; i++)
            {
                Console.WriteLine("ingrese [{0}] valor", i + 1);
                le = int.Parse(Console.ReadLine());
            }
            Console.WriteLine("--------- MENU ---------");
            Console.WriteLine("1. burbuja");
            Console.WriteLine("2. seleccion");
            Console.WriteLine("3. insercion");
            Console.WriteLine("4. shell");
            Console.WriteLine("5. quicksort");
            int a = int.Parse(Console.ReadLine());
            switch (a)
            {
             case 1:
                {   Console.WriteLine("ascendente o descendente [a/d] ");
                    string r=Console.ReadLine();
                    if (r == "a")
                    {   asburbuja(le,t);
                        recorrer(le,t);
                    }
                    if (r == "d")
                    {   desburbuja(le, t);
                        recorrer(le, t);
                    }
                 break;
                }
            case 2:
                {
                    Console.WriteLine("ascendente o descendente [a/d] ");
                    string r = Console.ReadLine();
                    if (r == "a")
                    {   selecionas(le, t);
                        recorrer(le, t);
                    }
                    if (r == "d")
                    {   seleciondes(le, t);
                        recorrer(le, t);
                    }
                    break;
                }
            case 3:
                {
                    Console.WriteLine("ascendente o descendente [a/d] ");
                    string r = Console.ReadLine();
                    if (r == "a")
                    {   insercionas(le, t);
                        recorrer(le, t);
                    }
                    if (r == "d")
                    {   inserciondes(le, t);
                        recorrer(le, t);
                    }
                    break;
                }
            case 4:
                {
                    Console.WriteLine("ascendente o descendente [a/d] ");
                    string r = Console.ReadLine();
                    if (r == "a")
                    {   shell(le, t);
                        recorrer(le, t);
                    }
                    if (r == "d")
                    {   shell1(le, t);
                        recorrer(le, t);
                    }
                    break;
                }
            case 5:
                {
                    Console.WriteLine("ascendente o descendente [a/d] ");
                    string r = Console.ReadLine();
                    if (r == "a")
                    {
                        quicksort(le, 0, le.Length - 1);
                        recorrer(le, t);
                    }
                    if (r == "d")
                    {   quicksort2(le, 0, le.Length - 1);
                        recorrer(le, t);
                    }
                    break;
                }
            }
            //fin Main
        }
    }
}


En línea

Meta


Desconectado Desconectado

Mensajes: 3.438



Ver Perfil WWW
Re: ejercicio en c#/tipo consola
« Respuesta #1 en: 7 Enero 2008, 22:30 pm »

Probando...



En línea

Meta


Desconectado Desconectado

Mensajes: 3.438



Ver Perfil WWW
Re: ejercicio en c#/tipo consola
« Respuesta #2 en: 7 Enero 2008, 22:32 pm »

En C# 3.5 o Visual C# 2008 no funciona.
En línea

revealer

Desconectado Desconectado

Mensajes: 24


Ver Perfil
Re: ejercicio en c#/tipo consola
« Respuesta #3 en: 16 Enero 2008, 02:54 am »

No puedo aportar en C#, lo siento, nada más queráa darte un consejo:
Si vas a publicar código usa el tag [ code ][ /code ] (sin espacios), es más legible asi...
Mucha suerte :D
En línea

ECDundy

Desconectado Desconectado

Mensajes: 8


throw new exception(":)");


Ver Perfil WWW
Re: ejercicio en c#/tipo consola
« Respuesta #4 en: 1 Mayo 2008, 01:21 am »

Estos son los errores que me da en .net 2003
C:\Class1.cs Line (236): Cannot implicitly convert type 'int' to 'int[]'
C:\Class1.cs Line (18): Operator '>' cannot be applied to operands of type 'int[]' and 'int'
C:\Class1.cs Line (20): Cannot implicitly convert type 'int[]' to 'int'
C:\Class1.cs Line (21): Cannot implicitly convert type 'int' to 'int[]'
C:\Class1.cs Line (35): Operator '<' cannot be applied to operands of type 'int[]' and 'int'
C:\Class1.cs Line (37): Cannot implicitly convert type 'int[]' to 'int'
C:\Class1.cs Line (38): Cannot implicitly convert type 'int' to 'int[]'
C:\Class1.cs Line (53): Cannot implicitly convert type 'int[]' to 'int'
C:\Class1.cs Line (54): Cannot implicitly convert type 'int' to 'int[]'
C:\Class1.cs Line (67): Cannot implicitly convert type 'int[]' to 'int'
C:\Class1.cs Line (68): Cannot implicitly convert type 'int' to 'int[]'
C:\Class1.cs Line (172): Operator '<' cannot be applied to operands of type 'int[]' and 'int'
C:\Class1.cs Line (180): Cannot implicitly convert type 'int[]' to 'int'
C:\Class1.cs Line (181): Cannot implicitly convert type 'int' to 'int[]'
C:\Class1.cs Line (199): Operator '>' cannot be applied to operands of type 'int[]' and 'int'
C:\Class1.cs Line (207): Cannot implicitly convert type 'int[]' to 'int'
C:\Class1.cs Line (208): Cannot implicitly convert type 'int' to 'int[]'

Tienes demasiado codigo iterado un codigo recursivo en la mayoria de los casos resolveria mucho mas rapido el problema
En línea

public void homework(){
for(int i=0;i<100;i++)Console.WriteLine("I will not throw paper airplanes in class");
}
Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
Consulta; ¿Que tipo de ejercicio les parece adecuado?
Programación C/C++
astinx 0 1,373 Último mensaje 10 Abril 2012, 15:15 pm
por astinx
Ejercicio java en consola
Java
shei 2 4,660 Último mensaje 10 Mayo 2012, 16:08 pm
por #Hianpaz
[Ejercicio] Sin usar tipo float
Programación C/C++
Miky Gonzalez 4 2,679 Último mensaje 10 Septiembre 2013, 19:31 pm
por do-while
Problema con ejercicio (tipo enum concretamente) SOLUCIONADO
Ejercicios
MCLucro 1 2,618 Último mensaje 22 Marzo 2015, 19:16 pm
por MCLucro
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines