vb@rchiv
VB Classic
VB.NET
ADO.NET
VBA
C#
Schützen Sie Ihre Software vor Software-Piraterie - mit sevLock 1.0 DLL!  
 vb@rchiv Quick-Search: Suche startenErweiterte Suche starten   Impressum  | Datenschutz  | vb@rchiv CD Vol.6  | Shop Copyright ©2000-2025
 
zurück

 Sie sind aktuell nicht angemeldet.Funktionen: Einloggen  |  Neu registrieren  |  Suchen

Visual-Basic Einsteiger
Re: Bubblesort?? 
Autor: BAStler
Datum: 06.05.08 20:45

Hallo Wayne,

habe hier noch ein Codeschnipsel gefunden. Ich weiß nicht genau, ob es auf Anhieb läuft, aber da kannst du die Funktionsweise auslesen.
' Bubblesort oder ShellSort
 
dim sortiert as Boolean
do
 sortiert = True
 For j = 1 To 6
  If a(i) < a(j) Then
   sortiert = False
   tmp = a(i)
   a(i) = a(j)
   a(j) = tmp
  End If  
 Next
 ' Ist das Array also bereits sortiert, endet die Schleife 
while until sortiert
 
 
Sub BubbleSortNumbers(iArray As Variant)
  Dim lLoop1 As Long
  Dim lLoop2 As Long
  Dim lTemp As Long
 
  startTime = Time()
  For lLoop1 = UBound(iArray) To LBound(iArray) Step -1
    For lLoop2 = LBound(iArray) + 1 To lLoop1
      If iArray(lLoop2 - 1) > iArray(lLoop2) Then
        lTemp = iArray(lLoop2 - 1)
        iArray(lLoop2 - 1) = iArray(lLoop2)
        iArray(lLoop2) = lTemp
      End If
    Next lLoop2
  Next lLoop1
  endTime = Time()
  timeToSort = endTime - startTime
  timeTaken = "Bubble Sort: " & timeToSort
End Sub
 
Sub SelectionSortNumbers(vArray As Variant)
  Dim lLoop1 As Long
  Dim lLoop2 As Long
  Dim lMin As Long
  Dim lTemp As Long
 
  startTime = Time()
  For lLoop1 = LBound(vArray) To UBound(vArray) - 1
    lMin = lLoop1
      For lLoop2 = lLoop1 + 1 To UBound(vArray)
        If vArray(lLoop2) < vArray(lMin) Then lMin = lLoop2
      Next lLoop2
      lTemp = vArray(lMin)
      vArray(lMin) = vArray(lLoop1)
      vArray(lLoop1) = lTemp
  Next lLoop1
  endTime = Time()
  timeToSort = endTime - startTime
  timeTaken = timeTaken & ";   Selection Sort: " & timeToSort
End Sub
 
Sub ShellSortNumbers(vArray As Variant)
  Dim lLoop1 As Long
  Dim lHold As Long
  Dim lHValue As Long
  Dim lTemp As Long
 
  startTime = Time()
  lHValue = LBound(vArray)
  Do
    lHValue = 3 * lHValue + 1
  Loop Until lHValue > UBound(vArray)
  Do
    lHValue = lHValue / 3
    For lLoop1 = lHValue + LBound(vArray) To UBound(vArray)
      lTemp = vArray(lLoop1)
      lHold = lLoop1
      Do While vArray(lHold - lHValue) > lTemp
        vArray(lHold) = vArray(lHold - lHValue)
        lHold = lHold - lHValue
        If lHold < lHValue Then Exit Do
      Loop
      vArray(lHold) = lTemp
    Next lLoop1
  Loop Until lHValue = LBound(vArray)
  endTime = Time()
  timeToSort = endTime - startTime
  timeTaken = timeTaken & ";   Shell Sort: " & timeToSort
End Sub
Falls nicht, einfach mal googeln!

Viel Erfolg
BAStler
alle Nachrichten anzeigenGesamtübersicht  |  Zum Thema  |  Suchen

 ThemaViews  AutorDatum
Bubblesort??1.386Wayne14106.05.08 20:29
Re: Bubblesort??921Zardoz06.05.08 20:44
Re: Bubblesort??1.203BAStler06.05.08 20:45
Re: Bubblesort??878Wayne14106.05.08 21:01
Re: Bubblesort??936BAStler06.05.08 21:24
Re: Bubblesort??951Wayne14106.05.08 21:58
Re: Bubblesort??959Wayne14107.05.08 12:04
Re: Bubblesort??937Zardoz07.05.08 13:52
Re: Bubblesort??829Wayne14107.05.08 19:19
Re: Bubblesort??765Brauner19.06.08 17:32
Re: Bubblesort??748Zardoz19.06.08 17:38

Sie sind nicht angemeldet!
Um auf diesen Beitrag zu antworten oder neue Beiträge schreiben zu können, müssen Sie sich zunächst anmelden.

Einloggen  |  Neu registrieren

Funktionen:  Zum Thema  |  GesamtübersichtSuchen 

nach obenzurück
 
   

Copyright ©2000-2025 vb@rchiv Dieter Otter
Alle Rechte vorbehalten.
Microsoft, Windows und Visual Basic sind entweder eingetragene Marken oder Marken der Microsoft Corporation in den USA und/oder anderen Ländern. Weitere auf dieser Homepage aufgeführten Produkt- und Firmennamen können geschützte Marken ihrer jeweiligen Inhaber sein.

Diese Seiten wurden optimiert für eine Bildschirmauflösung von mind. 1280x1024 Pixel