View previous topic :: View next topic |
Author |
Message |
Orcino
Joined: 07 Sep 2003 Posts: 56
|
Bubble sort in struct |
Posted: Sun Nov 26, 2006 3:00 pm |
|
|
Hi, how to use a bubble sort in struct below for var distancia ?
thanks
Orcino
Code: |
struct SGPSCoord
{
int32 buffer_latitude;
int32 buffer_longetude;
int16 distancia;
int8 status;
};
struct SGPSCoord GPSCOORD[100];
|
|
|
|
jma_1
Joined: 08 Feb 2005 Posts: 147 Location: Wisconsin
|
|
Posted: Sun Nov 26, 2006 4:49 pm |
|
|
Greetings,
Try using the search utility built into the forum. Searching for 'bubble' I came up with a posting by another forum member which provided sample code for a bubble sort.
http://www.ccsinfo.com/forum/viewtopic.php?t=25168&highlight=bubble
All sorts (bubble, selection, etc) are well known algorithms and are in any programming text book as well as online (bubble sort in google returns to many hits to count).
Did you look for bubble sort anywhere? Is the question how to access members of a structure? Again, there are numerous examples of this in the CCS files themselves (CAN library, etc) as well as in previous posts.
JMA |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Nov 26, 2006 5:08 pm |
|
|
I think this is homework. I'm not going to do your homework for you,
but I think your question is about how to swap two structures. The
swap is the main part of a bubble sort. Here's a macro to swap two
structures. You do the rest of it.
Code: |
struct SGPSCoord temp_struct;
#define swap(x,y) temp_struct = x; x = y; y = temp_struct;
|
|
|
|
|