![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Nov 2007
Posts: 5
Rep Power: 0
![]() |
Degree project help! Sorting an array
Right, We were set the task of designing a program for a fictional company "Loud music". I've come to a point in the code which i've never crossed before, i have to sort my array into ascending order. I've no idea how to sort an array, i've looked at numerous tutorials on numerous websites, and come to the conclusion bubble sort would be best? but can't apply it. This is the code:
Dim totalbr0(1 To 8) As Single
Private Sub cmdsearch_Click()
totalbr0(1) = 0
totalbr0(2) = 0
totalbr0(3) = 0
totalbr0(4) = 0
totalbr0(5) = 0
totalbr0(6) = 0
totalbr0(7) = 0
totalbr0(8) = 0
Dim startweek As Integer
Dim endweek As Integer
If txtweek1.Text = "" Then
txtweek1.Text = txtweek.Text
End If
startweek = Val(txtweek.Text)
endweek = Val(txtweek1.Text)
Dim filename As String
filename = App.Path & "\productdata.csv"
Open filename For Input As #1
Do
Input #1, branch, week, prod, Item, gen, sales
Dim fileweek As Integer
fileweek = Val(week)
If fileweek >= startweek And fileweek <= endweek Then
If branch = "br01" Then
totalbr0(1) = totalbr0(1) + sales
End If
If branch = "br02" Then
totalbr0(2) = totalbr0(2) + sales
End If
If branch = "br03" Then
totalbr0(3) = totalbr0(3) + sales
End If
If branch = "br04" Then
totalbr0(4) = totalbr0(4) + sales
End If
If branch = "br05" Then
totalbr0(5) = totalbr0(5) + sales
End If
If branch = "br06" Then
totalbr0(6) = totalbr0(6) + sales
End If
If branch = "br07" Then
totalbr0(7) = totalbr0(7) + sales
End If
If branch = "br08" Then
totalbr0(8) = totalbr0(8) + sales
End If
End If
Loop Until EOF(1)
Close #1
End SubI'm not asking anyone to do my "schoolwork" for me, i'm hoping someone will be able to lay out what i'd have to do in lamens terms because im a novice programmer, and up to now the program was going quite well. Thankyou. |
|
|
|
|
|
#2 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
Re: Degree project help! Sorting an array
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#3 | |
|
Newbie
Join Date: Nov 2007
Posts: 5
Rep Power: 0
![]() |
Re: Degree project help! Sorting an array
Quote:
|
|
|
|
|
|
|
#4 | |
|
Professional Programmer
Join Date: May 2006
Location: UK - London
Posts: 329
Rep Power: 3
![]() |
Re: Degree project help! Sorting an array
How did you arrive at that?
__________________
Quote:
|
|
|
|
|
|
|
#5 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
Re: Degree project help! Sorting an array
So you only want us to do HALF your work for you? How about an explanation, instead. No frills for optimization.
Compare the first element to every other element in the array. If the compared element is smaller, swap 'em and continue. This will bubble the smallest item to the top. Move to the second element. Come it to every remaining element in the array. Swap if necessary. Rinse and repeat until done. For a descending sort, reverse the nature of the comparison.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#6 |
|
Newbie
Join Date: Nov 2007
Posts: 5
Rep Power: 0
![]() |
Re: Degree project help! Sorting an array
how is explaining the concept of a bubble sort and how it's done DOING half the work for me?
Thankyou for the explanation, it made more sense than most of the tutorials that i've looked at on the internet. I'll attempt to apply it. |
|
|
|
|
|
#7 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
Re: Degree project help! Sorting an array
Writing pseudocode, as you asked, would be doing half the work for you. You'd only need a translator, not a thought process.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#8 |
|
Newbie
Join Date: Nov 2007
Posts: 5
Rep Power: 0
![]() |
Re: Degree project help! Sorting an array
by writing pseudo code i literally just meant, could you write the standard form of a bubble sort
for example an if statement as if (condition, statement) i don't want someone to literally just write the code so i can copy it, that's of no use to me. I want to learn it, because without learning it i could be questioned on it and not know what i'm talking about. |
|
|
|
|
|
#9 | ||
|
12 years old
Join Date: Nov 2007
Posts: 80
Rep Power: 1
![]() |
Re: Degree project help! Sorting an array
Quote:
Quote:
|
||
|
|
|
|
|
#10 |
|
Newbie
Join Date: Nov 2007
Posts: 5
Rep Power: 0
![]() |
Re: Degree project help! Sorting an array
Managed to get it working, and now i've done it i actually understand a bubble sort.
Thanks dawei and null_ptr0 |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| tasm sorting 5 integers with array | akioshin | Assembly | 15 | Oct 30th, 2007 1:45 AM |
| sorting an array by field | cwl157 | C | 4 | Apr 4th, 2007 2:48 PM |
| Sorting an array of objects | oNe8 | Java | 2 | Feb 22nd, 2006 10:59 PM |
| Sorting a Numeric Array | little_valaree | Java | 2 | Nov 21st, 2005 11:00 AM |
| Installing IPB 2.03 | bh4575 | Other Web Development Languages | 0 | Apr 23rd, 2005 2:36 AM |