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

 

 


Tema destacado: Recopilación Tutoriales y Manuales Hacking, Seguridad, Privacidad, Hardware, etc


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  .NET (C#, VB.NET, ASP) (Moderador: kub0x)
| | | |-+  AYUDA C#!!! COMO ORDENAR UAN LISTA
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: AYUDA C#!!! COMO ORDENAR UAN LISTA  (Leído 10,178 veces)
neo_angel_xxx

Desconectado Desconectado

Mensajes: 2


Ver Perfil
AYUDA C#!!! COMO ORDENAR UAN LISTA
« en: 27 Octubre 2010, 18:50 pm »

POZ TENGO UN TRABAJO PARA LA UNIVERSIDAD DE HACER UN MENU CON ALGUNOS METODOS TALES COMO ORDENAR LISTAR ELIMINAR BUSCAR POSICION Y ORDENAR UNA LISTA... YA LOS HICE TODOS PERO NOCE COMO HACER EL ULTIMO QUE ES ORDENAR HMM... ES UNA LISTA SIMPLE (ENLAZADA).. AVER SI ME PUEDEN AYDUAR PORFAVRO CON UN MODULITO PARA ORDENAR... LES PASO HASTA EL MOMENTO MI PROGRAMA(CONSOLA)^^,!!
1....Cree un nuevo proyecto Biblioteca de Clases en Visual C#.Net con el nombre de “Clase_Lista” :
 Agregue una clase con el nombre “CLista.cs” con el siguiente código dentro de la clase.

namespace CLASE_LISTA
{
    public class cLista
    {
        //---atributo
        private CNodo aPrimerNodo;
        private CNodo aUltimoNodo;
        private string dato;
      // referencia a la cabeza de la lista
        //---constructor: construye una lista vacia
        public cLista()
        {
            aPrimerNodo = null;
            aUltimoNodo = null;
           
        } //fin del constructor
        //Propiedad
        public CNodo PrimerNodo
        {
            get
            {
                return aPrimerNodo;
            }
            set
            {
                aPrimerNodo = value;
            }
        }
        public CNodo UltimoNodo
        {
            get
            {
                return aUltimoNodo;
            }
            set
            {
                aUltimoNodo = value;
            }
        }
        //Metodos
        //---determina si la lista esta vacia
        public bool estaVacia()
        {
                         
            return aPrimerNodo == null;
           
        }
        public void InsertarP(string item, int pos)
        {
            CNodo aux = new CNodo();
            aux.Elemento = item;
            aux.SgteNodo = null;
            if (PrimerNodo == null)
            {
                Console.WriteLine(" LISTA VACIA,SE INSERTA EN LA 1ºPOSICION");
                PrimerNodo = aux;
            }
            else
            {
                CNodo puntero;
                puntero = PrimerNodo;
                if (pos == 1)
                {
                    PrimerNodo = aux;
                    aux.SgteNodo = puntero;
                }
                else
                {
                    for (int i = 1; i < pos - 1; i++)
                    {
                        puntero = puntero.SgteNodo;
                        if (puntero.SgteNodo == null)
                            break;
                    }
                    CNodo punteronext;
                    punteronext = puntero.SgteNodo;
                    puntero.SgteNodo = aux;
                    aux.SgteNodo = punteronext;
                }
            }
        }
        //insertar final de la lista
        public void agregarf(string item)
        {
            CNodo aux = new CNodo();
            aux.Elemento = item;
            aux.SgteNodo = null;
            if (PrimerNodo == null)
                PrimerNodo = aux;
            else
            {
                CNodo puntero;
                puntero = PrimerNodo;
                while (puntero.SgteNodo != null)
                {
                    puntero = puntero.SgteNodo;
                }
                puntero.SgteNodo = aux;
            }
        }
        public int longitud()
        {
            CNodo nodoAux; //nodo auxiliar
            int i = 0; //contador de nodos
            nodoAux = aPrimerNodo;
            while (nodoAux != null)
            {
                i++;
                nodoAux = nodoAux.SgteNodo;
            }
            //---devuelve la longitud de la lista
            return i;
        } // fin del metodo longitud
        //---agrega un elemento al frente de la lista
        public void agregari(string elemento)
        {
            aPrimerNodo = new CNodo(elemento, aPrimerNodo);
        }
        //Eliminar inicio de la lista
        public void eliminarI()
        {
            if (PrimerNodo == null)
                Console.WriteLine("Lista vacía, no se puede eliminar");
            else
                PrimerNodo = PrimerNodo.SgteNodo;
        }
        //Eliminar final de la lista
        public void eliminarF()
        {
            if (PrimerNodo == null)
                Console.WriteLine("Lista vacía, no se puede eliminar");
            else
                if (PrimerNodo.SgteNodo == null)
                    PrimerNodo = null;
                else
                {
                    CNodo punteroant, punteronext;
                    punteroant = PrimerNodo;
                    punteronext = PrimerNodo;
                    while (punteronext.SgteNodo != null)
                    {
                        punteroant = punteronext;
                        punteronext = punteronext.SgteNodo;
                    }
                    punteroant.SgteNodo = null;
                }
        }
 
       
        public Object contenido(CNodo ubicacion)
        {
            return ubicacion.Elemento;
        }// fin de contenido
        public CNodo acceso(int i)
        {
            CNodo nodoAux; //nodo auxiliar
            nodoAux = null;
            if (!(estaVacia()) && (i <= longitud()))
            { //---la lista no es vacia
                //---nodoAux toma el primer nodo de la lista
                nodoAux = PrimerNodo;
                //---ubicar n-esimo nodo
                while (i > 1)
                {
                    --i;
                    nodoAux = nodoAux.SgteNodo;
                }
            }

            return nodoAux; //valor que retorna el metodo
        }//fin del metodo acceso
        public Object iesimo(int i)
        {
            return contenido(acceso(i));
        } //fin de iesimo
        public void listar()
        {
            if (longitud() == 0)
                Console.WriteLine("lista vacia");
            else
            {
                int i;
                //---imprimir elementos de la lista
                for (i = 1; i <= longitud(); i++)
                {
                    Console.WriteLine(iesimo(i));
                }
            }
        }// fin de listar
     
       
        }

2.... Agregue una clase con el nombre “CNodo.cs” con el siguiente código dentro de la clase.

namespace CLASE_LISTA
{
    public class CNodo
    {
        //---atributos
        private string dato;
        private CNodo aSgteNodo;
   
        //---constructor: crea un nodo que contiene elemento
        public CNodo()
        {
            dato = null;
            aSgteNodo = null;
         
        }
        public CNodo(string pElemento, CNodo pSgteNodo)
        {
            dato= pElemento;
            aSgteNodo = pSgteNodo;
       
        }
        //Propiedades
        public string Elemento
        {
            get
            {
                return dato;
            }
            set
            {
                dato = value;
            }
        }
        //---metodo retorna siguiente nodo
        public CNodo SgteNodo
        {
            get
            {
                return aSgteNodo;
            }
            set
            {
                aSgteNodo = value;
            }
        }
       
    }
3............ Cree un nuevo proyecto de Aplicación de Consola, agregue una Referencia a su proyecto (Clase_Lista) y agregue el siguiente código dentro de la clase Program.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CLASE_LISTA;

namespace listas1._.codificacion
{
    class Program
    {

        static void Menu()
        {
            Console.WriteLine("M E N U");
            Console.WriteLine("==================================");
            Console.WriteLine("1. Agregar al inicio.");
            Console.WriteLine("2.Agregar al final");
            Console.WriteLine("3. Mostrar lista.");
            Console.WriteLine("4.ingresar elemento en una posicion determinada");
            Console.WriteLine("5.Borrar del final");
            Console.WriteLine("6.Borrar del inicio");
            Console.WriteLine("7. Salir");
            Console.WriteLine("ingrese una opcion");
            Console.WriteLine("==================================");
        }
        static void Pausa()
        {
            Console.WriteLine("\nPulse [ENTER] para continuar ingresando otra opcion...");
            Console.ReadLine();
        }
        static void Main(string[] args)
        {
            cLista OLista = new cLista();
            //---crear los objetos que contendra la lista
            int opcion = 0;
         
            while (opcion != 7)
            {
                Console.Clear();
                Menu();

                opcion = int.Parse(Console.ReadLine());

                switch (opcion)
                {
                    case 1:
                        Console.WriteLine("ingrese elemento:");
                        string el = Console.ReadLine();
                        OLista.agregari(el);
                        Pausa();
                        break;
                    case 2:
                        Console.WriteLine("ingrese elemento:");
                        string ele = Console.ReadLine();
                        OLista.agregarf(ele);
                        Pausa();
                        break;
                    case 3:
                        Console.WriteLine("la lista es:");
                        OLista.listar();
                        Console.WriteLine("longitud: " + OLista.longitud());
                                           
                        Pausa();
                        break;
                    case 4:
                        Console.WriteLine("ingrese la posicion en la que desea ingresar elemento");
                        int posi = int.Parse(Console.ReadLine());
                        Console.WriteLine("ingrese el elemento a ingresar");
                        string ele1 = Console.ReadLine();
                        OLista.InsertarP(ele1,posi);
                        Pausa();
                        break;
                    case 5:
                        Console.WriteLine("Eliminando de la posicion final");
                        OLista.eliminarF();
                        Pausa();
                        break;
                    case 6:
                        Console.WriteLine("eliminando de la primera posicion");
                        OLista.eliminarI();
                        Pausa();
                        break;
                 
                }
            }
}
}


«-------------AYUDA PLEASe!!!!!!!!!!1


En línea

Khronos14


Desconectado Desconectado

Mensajes: 443


A lie is a lie


Ver Perfil WWW
Re: AYUDA C#!!! COMO ORDENAR UAN LISTA
« Respuesta #1 en: 27 Octubre 2010, 19:42 pm »

C# al igual que Java tiene clases para todo, es programación para tontos, todo te viene hecho e implementado. Los arrays y listas tienen un método llamado Sort() que te ordena los elementos.

De todas formas, no es muy difícil implementar un algoritmo de ordenación: tienes el método de la burbuja, el quicksort, el shell, etc..

PD: Léete las normas y utiliza Geshi para resaltar el código.

Saludos.


En línea

[D4N93R]
Wiki

Desconectado Desconectado

Mensajes: 1.646


My software never has bugs. Its just features!


Ver Perfil WWW
AYUDA C#!!! COMO ORDENAR UAN LISTA
« Respuesta #2 en: 27 Octubre 2010, 19:43 pm »

El mensaje 'AYUDA C#!!! COMO ORDENAR UAN LISTA' fue bloqueado
No se hacen tareas, leer las normas.
Leer reglas:
http://foro.elhacker.net/reglas
En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
AYUDA ORDENAR LISTA SIMPLE[C]
Programación C/C++
HRSLASH 0 9,110 Último mensaje 23 Abril 2011, 04:22 am
por HRSLASH
Problema al ordenar lista c++.
Programación C/C++
Gaspi 6 3,732 Último mensaje 20 Febrero 2015, 22:53 pm
por Gaspi
Problema al ordenar una Lista Doble(Lectura de XML)
Programación C/C++
falconez 1 1,943 Último mensaje 23 Febrero 2015, 03:25 am
por falconez
javascript - Ordenar por encabezados en forma de lista
Programación General
VicInFlames 0 1,666 Último mensaje 2 Noviembre 2015, 21:18 pm
por VicInFlames
Ordenar lista de usuarios basados en el año
PHP
Antoniio 1 2,333 Último mensaje 4 Noviembre 2016, 22:44 pm
por SetzerFF
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines