![]() |
|
|||||||
| Proton Plus Compiler v3 Coding problems and general discussion related to the Development Suite |
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
#1 |
|
Licensed User
![]() Join Date: Jan 2009
Location: London
Posts: 51
![]() |
I need to do a Bubble sort on a two element array on a F88 - you know Array(a,b), the sort looks at the value of 'b' and sorts it by the highest to lowest value (byte), 'a' (Word) is another value which obviously needs to stay with the correct 'b' it is associated with.
Have no idea how to do that, so any help or pointers in the right direction would be greatly appreciated. Thanks |
|
|
|
|
|
#2 |
|
Licensed User
![]() Join Date: Jul 2004
Posts: 605
![]() |
For basic sorting see samples folder for BUBBLE_SORT and BUBBLE2.
Norm Last edited by normnet; 2nd February 2010 at 09:58. |
|
|
|
|
|
#3 |
|
Licensed User
![]() Join Date: Jan 2009
Location: London
Posts: 51
![]() |
Thanks Norm but where is that folder? I have looked on the forum and in my installation folders but cannot find the folder.
|
|
|
|
|
|
#4 |
|
Licensed User
![]() Join Date: Jan 2009
Location: London
Posts: 51
![]() |
I have done a lot of search I think, and have found samples of Bubble Sort thanks to Tim Box, that is fine, I think I can even deal with the Word size of it however, my problem is with having to deal with the second element in the array. Seeing as Proton cannot do two element arrays, I would need to deal with the second element in a way to sync it with the bubble sorted element, that's where I get stuck!
Maybe there is a totally different way to deal with this apart from using Bubble Sort. I have an Array(16bit _address, Signal_Level) the array count is say 3. What I need to do is to find out which of the elements have the highest signal level and then sort them with highest Signal_Level and its 16bit_address at the top and so on to the lowest (3rd). Any ideas? Thanks very much. |
|
|
|
|
|
#5 | |
|
Licensed User
![]() Join Date: Jul 2004
Posts: 605
![]() |
Quote:
Are you doing a 2 dimensional array? I didn't realize Proton could do 2 dimensional arrays. Norm |
|
|
|
|
|
|
#6 |
|
Licensed User
![]() Join Date: Aug 2004
Location: Keighley, West Yorkshire
Posts: 24
![]() |
Here's a possible solution based on the sample:
Code:
' This subroutine implements a technique called "bubble sort."
BUBBLE_SORT:
Repeat
SWAP_OCCURED = 0
INDEX = 0
Repeat
If SAMPLE[INDEX] > SAMPLE[INDEX + 1] Then
SWAPTMP = SAMPLE[INDEX]
SWAPTMP2 = ARRAY2[INDEX]
SAMPLE[INDEX] = SAMPLE[INDEX + 1]
ARRAY2[INDEX] = ARRAY2[INDEX+1]
SAMPLE[INDEX + 1] = SWAPTMP
ARRAY2[INDEX+1] = SWAPTMP2
SWAP_OCCURED = 1
Endif
Inc INDEX
Until INDEX = SAMPLES_TO_TAKE
Until SWAP_OCCURED = 0
Return
Brian |
|
|
|
|
|
#7 |
|
Licensed User
![]() Join Date: Jan 2009
Location: London
Posts: 51
![]() |
Norm, yes I am trying to do a 2 dimensional array and no from memory (6 months ago) I read somewhere I think in the manual (Help) that Proton can NOT do 2 dimensional - thats why I am stuck trying to do it in one way or another, there must be some way of doing it.
I already looked in the path for the samples folder but I have only two folder in there MCLoader and Plugin, I updated to the latest version 3.0.4.5 and 2.0.0.4 a while back following the upgrade instructions. In any case, standard 1 dimensional bubble sort I have samples of and Brian has added one here - I need to find a way of doing a 2 dimensional on if it is possible. Thank you Brian, but as mentioned above, I need a 2 dimensional sort. |
|
|
|
|
|
#8 |
|
Licensed User
![]() Join Date: May 2008
Location: Sydney, Australia
Posts: 1,453
![]() |
How do you expect to get help for a multidimensional sort algorithm in a language that doesn't support multiple dimensions? First we need a multidimensional array!
What is your exact application? It may be easier get your end result a different way. The latest version is 3.4.0.8 The sample folder is in your |
|
|
|
|
|
#9 |
|
Licensed User
![]() Join Date: Feb 2004
Location: Aberdeen Scotland
Posts: 1,220
![]() |
Should be possible by using two arrays for the data and using pointers instead of shifting the data around. Try Googling:-
sorting arrays +pointers +basic |
|
|
|
|
|
#10 |
|
Licensed User
![]() Join Date: Jul 2004
Posts: 605
![]() |
Bubble sort samples from compiler 3.2.5.5
Norm |
|
|
|
|
|
#11 |
|
Licensed User
![]() Join Date: Jan 2009
Location: London
Posts: 51
![]() |
Wastrix, I didnt expect multidimensional command implemented into Proton for me, I understand that is not possible
, not as articulated though I meant exactly what you say "It may be easier get your end result a different way", there are always ways around things right?I have 3 transmitters sending data from various points, each have a 16bit address; I also have a receiver, receiving the data transmitted by the transmitters (data and their 16 bit address), the receiver needs to do the following for all the transmissions: Store the 16 bit address of the transmitter, AND store the Signal_Level associated with that transmitter. Do that for all transmitters until a table/array is filled. Then rearrange (bubble sort) the above table/array (or whatever) in to a sorted table/array arranged at the top with the highest signal_Level AND its 16 bit_Address Hope that makes enough sense, I did try to explain this in one of my posts above. See_Mos Thank you thats the kind of stuff I am looking for, ways around the block. I am searching now, if you find anything specific please let me know. Norm, Thank you very much fro the attachments, good for reference but I need a way to do multidimensional. I am new to Pic Basic, but years and years ago I did assembler/C/Basic but I am way too rusty now to figure out a way around this challenge.Thanks for your input guys. |
|
|
|
|
|
#12 |
|
Licensed User
![]() Join Date: Jan 2004
Location: Wellington, New_Zealand
Posts: 724
![]() |
the answer is right there! (BrianPS).
Bubble sort the level array but manipulate the content of both arrays at the same time. Paul V. |
|
|
|
|
|
#13 |
|
Licensed User
![]() Join Date: Aug 2004
Location: Keighley, West Yorkshire
Posts: 24
![]() |
Simon, my original post gives the answer you require, thanks Paul V for the support.
The solution uses two arrays: sample is your word array and array2 is the associated byte array, and as Paul rightly points out it adjust both arrays at the same time, locking both word & byte arrays together. Brian |
|
|
|
|
|
#14 |
|
Licensed User
![]() Join Date: May 2008
Location: Sydney, Australia
Posts: 1,453
![]() |
Ahhh... I think I am correct in saying that in you application, you do not need a two dimensional array (square table of values), just a one dimensional array capable of storing a byte and a word in each index.
In which case, Brian's solution of using two arrays would work. |
|
|
|
|
|
#15 |
|
Licensed User
![]() Join Date: Aug 2004
Location: Central Scotland
Posts: 1,599
![]() |
My old tutor, to give a better understanding of multi-dimensional arrays, and how to use these, taught us to treat multi-dimensional arrays as multiple single dimensional (1*x) arrays which were index linked which is basically what BrianPS has described.
So maybe you can't declare multi-dimensional arrays in Proton. Big deal. You can declare multiple single dimensional arrays. With index linking you can index link any number of single dimension arrays according to your needs effectively creating multi-dimensional arrays. Proton can work with single dimension arrays, so using index linking you should be able to create custom multi-dimensional arrays for use in Proton. One method of keeping track of which single dimension array does what is to give each a name which more-or-less describes the data in the array. Oops! Shut up Bill! You just re-invented the spreadsheet. ![]() BTW Wastrix, any array with more than one column and row is multi-dimensional.
Last edited by bill9399; 3rd February 2010 at 22:06. |
|
|
|
|
|
#16 |
|
Licensed User
![]() Join Date: May 2008
Location: Sydney, Australia
Posts: 1,453
![]() |
I am well are aware that this is a two dimensional array (x by 2), however the situation is different to an x by y array, in which case you would need an array of arrays which is not really supported in PDS, unless you directly access the RAM.
oh well...
|
|
|
|
|
|
#17 |
|
Licensed User
![]() Join Date: Jan 2009
Location: London
Posts: 51
![]() |
BrianPS, yes it does, thank you very much. I missed that as I have been pouring over so many samples lately. I did say I was rusty and multidimensional arrays were always one of my weak points and there are many these days
![]() I will try to implement my code using the sample as a template. Thank you all again very much for taking the time to show me something that I should have seen when BrianPS originally posted. Cheers |
|
|
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Using an alias to a byte array element ? is it possible ? | captainslarty | Proton Plus Compiler v3 | 6 | 12th March 2009 13:39 |
| Division with an array element - easy question | HelpMe! | Proton Plus Compiler v3 | 9 | 14th June 2008 10:31 |
| Memristor, a new circuit element. | Ken_K | The Lounge | 2 | 19th May 2008 17:50 |
| Syntax error when aliasing array element? | RGV250 | Proton Plus Compiler v3 | 4 | 6th April 2007 23:16 |
| Alias of Byte Array Element Bit | picnaut | Proton Plus Compiler v3 | 3 | 21st November 2004 20:25 |