Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Otros entornos y lenguajes > Lazarus, FreePascal, Kylix, etc.
Registrarse FAQ Miembros Calendario Guía de estilo Buscar Temas de Hoy Marcar Foros Como Leídos

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 02-03-2010
bothy bothy is offline
Miembro
 
Registrado: ene 2010
Posts: 144
Poder: 15
bothy Va por buen camino
metodo de la burbuja

Quisiera saber Como hago el metodo de la burbuja en delphi 2009 . . .
teniendo un listbox y un vector. . para ordenar numeros ya que sort los ordena alfabeticamente..
Responder Con Cita
  #2  
Antiguo 02-03-2010
Avatar de Neftali [Germán.Estévez]
Neftali [Germán.Estévez] Neftali [Germán.Estévez] is offline
[becario]
 
Registrado: jul 2004
Ubicación: Barcelona - España
Posts: 18.233
Poder: 10
Neftali [Germán.Estévez] Es un diamante en brutoNeftali [Germán.Estévez] Es un diamante en brutoNeftali [Germán.Estévez] Es un diamante en bruto
Para un array de enteros puedes usar algo así:

Código Delphi [-]
procedure TBubbleSort.Sort(var A: array of Integer);
var
  I, J, T: Integer;
begin
  for I := High(A) downto Low(A) do
    for J := Low(A) to High(A) - 1 do
      if A[J] > A[J + 1] then
      begin
        VisualSwap(A[J], A[J + 1], J, J + 1);
        T := A[J];
        A[J] := A[J + 1];
        A[J + 1] := T;
        if Terminated then Exit;
      end;
end;

Para un TStringList:

Código Delphi [-]
function BubbleSort( list: TStringList ): TStringList;
var
  i, j: Integer;
  temp: string;
begin
  // bubble sort
  for i := 0 to list.Count - 1 do begin
    for j := 0 to ( list.Count - 1 ) - i do begin
      // Condition to handle i=0 & j = 9. j+1 tries to access x[10] which
      // is not there in zero based array
      if ( j + 1 = list.Count ) then
        continue;
      if ( list.Strings[j] > list.Strings[j+1] ) then begin
        temp              := list.Strings[j];
        list.Strings[j]   := list.Strings[j+1];
        list.Strings[j+1] := temp;
      end; // endif
    end; // endwhile
  end; // endwhile
  Result := list;
end;

Si buscas en los foros, también encontrarás links muy interesantes (link, link, link)

Si deseas versiones alternativas, seguro que por internet encuentras muchas más.
__________________
Germán Estévez => Web/Blog
Guía de estilo, Guía alternativa
Utiliza TAG's en tus mensajes.
Contactar con el Clubdelphi

P.D: Más tiempo dedicado a la pregunta=Mejores respuestas.
Responder Con Cita
  #3  
Antiguo 03-03-2010
bothy bothy is offline
Miembro
 
Registrado: ene 2010
Posts: 144
Poder: 15
bothy Va por buen camino
Buscaba algo mas facil pero con esta ayuda logre hacer mi metodo de la burbuja .. problema resuelto
Responder Con Cita
Respuesta


Herramientas Buscar en Tema
Buscar en Tema:

Búsqueda Avanzada
Desplegado

Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
Mensaje en burbuja amarilla de windows jorgegetafe Varios 9 26-07-2007 14:48:08
ordenacion de un array mediante el metodo de la burbuja baby Varios 11 08-05-2007 03:43:55
metodo de burbuja utilizando el random() soma25 C++ Builder 3 21-06-2006 02:36:15
Metodo locate fefe13 Conexión con bases de datos 3 06-11-2005 14:09:22
Metodos de Ordenamiento. QuickSort vs Burbuja Mejorado Delphius Varios 9 22-07-2005 03:37:50


La franja horaria es GMT +2. Ahora son las 19:53:27.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi