473,320 Members | 2,006 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

sorting a structure...?

well I have a template of a structure...but when I try to add something to sort the list (an attempt at a bubble sort[our instructor gave us a template about a bubble sort but I'm having troubles following it]), I'm running into some problems....any input would be appreciated, thanks

this is all inside of a struct a[...]

(program runs and user have 2 options of either entering a new item, and sorting that listed items...the entering a new item part I'm done but the sorting I'm having some trouble)

the errors that come up
"invalid operators to binary>" (line with "if statement")
"incompatible types in assignment" (line inside of if statement : t=...)
"incompatible types in assignment" (same line as above)


void sort(void)

{
int j, t;

for(j=1; j && n; j++)
{
if(a[j-1] > a[j]);
{
t = a[j-1]; a[j-1] = a[j]; a[j]=t;
}
}
printf("\nSorted List:\n");
for (n=0; n < j; n++) // print sorted list
printf("Name: %s\n", j+1, a[j]);
}
Dec 7 '09 #1
3 1903
newb16
687 512MB
How do you know that struct a a1 is less than struct a a2?
Dec 7 '09 #2
sorry I'm not too sure what you mean? Do you mean in the if statement?
Dec 8 '09 #3
RRick
463 Expert 256MB
Your problem is with various comparisons and assignments for the variable called a. They will only work is a[j] is a number, which means the variable a must be an array of ints or some other type of number.

If a is an array of objects or structs, you have to define how the operators work.
Dec 8 '09 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: York | last post by:
Lets say I have the following structure struct test_struct { int some_number; char first_name } test_struct s_table
2
by: yee young han | last post by:
I need a fast data structure and algorithm like below condition. (1) this data structure contain only 10,000 data entry. (2) data structure's one entry is like below typedef struct _DataEntry_...
7
by: Karin Jensen | last post by:
Hi I am running a PHP program that connects to an Access 2000 database via ODBC: $results = odbc_exec($connection_id, $sql_select); Is it possible to sort the contents of $results? I wish to...
8
by: Mike MacSween | last post by:
tblCourses one to many to tblEvents. A course may have an intro workshop (a type of event), a mid course workshop, a final exam. Or any combination. Or something different in the future. At...
11
by: rkbnair | last post by:
I have created a datagrid in my aspx with the 'AllowSorting' property to true. When clicking on the column header, the page refreshes. However the sorting is not done. Am I missing anything? I...
4
by: rushik | last post by:
Hello all, I am using structure in my program, and my aim is to sort this structure based on some optimized sorting algo. structure is struct data { int account;
3
by: Pino | last post by:
HI all, I am learning c++ ( just 1 month) and would want an aid for a code. I have a integer vector of length N. ie 3 3 3 4 4 1
3
KevinADC
by: KevinADC | last post by:
If you are entirely unfamiliar with using Perl to sort data, read the "Sorting Data with Perl - Part One and Two" articles before reading this article. Beginning Perl coders may find this article...
12
by: Justin | last post by:
Ok, I give up. I can't seem to construct a decent (productive) way of sorting my arraylist. I have a structure of two elements: Structure TabStructure Dim TabName As String Dim FullFilePath...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.