elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.
 
Inicio Ayuda Ingresar Registrarse
08 Octubre 2008, 12:07  



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

Desconectado Desconectado

Mensajes: 3


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

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: 992


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

Probando...

En línea

http://usuarios.lycos.es/electronicapic Manuales de electrónica general y PIC.
Meta

Desconectado Desconectado

Mensajes: 992


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

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

http://usuarios.lycos.es/electronicapic Manuales de electrónica general y PIC.
revealer

Desconectado Desconectado

Mensajes: 22


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

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: 01 Mayo 2008, 01:21 »

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 Imprimir 
Ir a:  







Consolas     La Web de Goku     MilW0rm     MundoDivx

Hispabyte     Truzone     TodoReviews     ZonaPhotoshop

hard-h2o modding    Foros de ayuda    Yashira.org    Videojuegos    indetectables.net   

Noticias Informatica    Seguridad Informática    ADSL    Foros en español    eNYe Sec

Todas las webs afiliadas están libres de publicidad engañosa.

Powered by SMF 1.1.6 | SMF © 2006-2008, Simple Machines LLC