|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
|
|
#1
|
|||
|
|||
ok i did a seach and found nothing i mean nothing so im really sorry if i upset anyone with my question.Ok here is what i have but ive been asked to take the text file and sort if it isnt organized. and to be honest i have no idea can someone plz exaplain to me the general idea? i was thinking about using Case select for it, all i need is help on sorting the text file and any advise would be very helpfull. this is also for school PHP Code:
Quote:
Last edited by astro86 : September 22nd, 2003 at 11:55 PM. |
|
#2
|
|||
|
|||
|
|
|
#3
|
|||
|
|||
|
Bubble samplecode:
Private Sub Form_Load() Dim x x = Array("hello", "this", "is", "silly", "hello", "this", "is", "silly", "34", "not") x = BubbleSort(x) For i = LBound(x) To UBound(x) MsgBox x(i), , i Next End Sub Private Function BubbleSort(ByVal myArray As Variant) As Variant Dim p, j, iCount As Integer Dim x As Variant 'check to see if paramater is an array If IsArray(myArray) Then ' count how many fields are in the array iCount = UBound(myArray) 'loop from n to n-1 (first time) For p = 0 To iCount - 1 'loop from n to n-p-1 (second time) 'after each time through this loop, the pth largest 'element is in the correct position 'p items are in the correct positions, so don't check them again For j = 0 To iCount - p - 1 ' check if current item is greater than the next item ' if so, swap If myArray(j) > myArray(j + 1) Then x = myArray(j) myArray(j) = myArray(j + 1) myArray(j + 1) = x End If Next j Next p 'return sorted array BubbleSort = myArray Else MsgBox "not an array" End If End Function let's say you have an array that looks like this: 1,9,3,4,2,5,10 bubble sort will do this: compare 10 and 5 10 > 5 so keep the same then compare 5 and 2 5 > 2 so keep the same then compare 2 and 4 2 < 4 so swap resulting in 1,9,3,2,4,5,10 then compare 2 and 3 2 < 3 so swap resulting in 1,9,2,3,4,5,10 then compare 2 and 9 2 < 9 so swap resulting in 1,2,9,3,4,5,10 then compare 2 and 1 2 > 1 so keep the same keep running through it until the array is sorted so right now we have 1,2,9,3,4,5,10 when it gets to comparing 3 and 9 3 < 9 so swap resulting in 1,2,3,9,4,5,10 repeat the process until the array is sorted... U can use it to sort the textfile lines by sequence of the price or another... |
|
#4
|
|||
|
|||
thank's CP that was very helpfull im almost done with it ill post it up once im done |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > Visual Basic Programming > Bubble Sorting and Txt File sorting help |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|