473,394 Members | 1,932 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,394 software developers and data experts.

Sorting by Alphabetical order using strings in data structures

22
Here is my problem:

Structure
typedef struct
{
char lname[25];
char fname[25];
int age;
double salary;
} employee_t;

I have read data in from a binary file (example):
Doe John 21 40000
(lastname) (firstname) (age) (salary)


PROBLEM

I am passing the structure to a function which sorts the last names in Alphabetical order.

void sort(employee_t*, int)
employee_t = the structure int = number of employees read in.

I need this sort function to sort those employees in alphabetical order.

If anyone can help me out by getting me started or helping me along that would be fantastic. I know I need to essentially use 2 "for" loops using a counters, and strcmp() some where within the loops. Some one help me please!
Apr 28 '07 #1
7 4401
Ganon11
3,652 Expert 2GB
Which sorting algorithm will you be using? For simplicity, I'd suggest the Selection Sort; for speed, I'd suggest the Quick Sort.

You say you are sorting the employees alphabetically...by first name? By last name? By some other variable?
Apr 28 '07 #2
Hold on, I'm writing you a function now...
Apr 28 '07 #3
Here's some sample code that should solve your problem. Right now it's sorting (Bubble Sort) by last name, but you can easily change that. I hope this helps!

<Code removed

MODERATOR>
Apr 28 '07 #4
Savage
1,764 Expert 1GB
Hold on, I'm writing you a function now...
And,u hold too hold on,first read posting guidelines.If u wish to help OP just write him a pseudocode and don't write him whole function!

I suggest to remove it before a moderator those.


Savage
Apr 28 '07 #5
And,u hold too hold on,first read posting guidelines.If u wish to help OP just write him a pseudocode and don't write him whole function!

I suggest to remove it before a moderator those.


Savage
Oops, didn't read them. You're right though, but how do I delete it?
Apr 28 '07 #6
Savage
1,764 Expert 1GB
Oops, didn't read them. You're right though, but how do I delete it?
Now u can't delete it,u can delete it only 5 minutes after u posted it.Only moderator/admin can delete it now.

Savage
Apr 29 '07 #7
Ganon11
3,652 Expert 2GB
Oops, didn't read them. You're right though, but how do I delete it?
I have taken care of it. Make sure you read through the Posting Guidelines when you get a chance ;)
Apr 30 '07 #8

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

Similar topics

4
by: dont bother | last post by:
This is really driving me crazy. I have a dictionary feature_vectors{}. I try to sort its keys using #apply sorting on feature_vectors sorted_feature_vector=feature_vectors.keys()...
7
by: Federico G. Babelis | last post by:
Hi All: I have this line of code, but the syntax check in VB.NET 2003 and also in VB.NET 2005 Beta 2 shows as unknown: Dim local4 As Byte Fixed(local4 = AddressOf dest(offset)) ...
22
by: mike | last post by:
If I had a date in the format "01-Jan-05" it does not sort properly with my sort routine: function compareDate(a,b) { var date_a = new Date(a); var date_b = new Date(b); if (date_a < date_b)...
6
by: Dennis Gearon | last post by:
This is what has to be eventually done:(as sybase, and probably others do it) http://www.ianywhere.com/whitepapers/unicode.html I'm not sure how that will affect LIKE and REGEX. ...
25
by: Allie | last post by:
How would I go about sorting this structure by title? typedef struct { char author; char title; char code; int hold; int loan; } LIBRARY;
9
by: Dylan Parry | last post by:
Hi folks, I have a database that contains records with IDs like "H1, H2, H3, ..., Hn" and these refer to local government policy numbers. For example, H1 might be "Housing Policy 1" and so on....
1
by: quirdan | last post by:
Hi, I am after some advice about which data structures I should use. I'm developing a program and I am at the point where all the strings are being generated and printed one by one with...
1
KevinADC
by: KevinADC | last post by:
Introduction In part one we discussed the default sort function. In part two we will discuss more advanced techniques you can use to sort data. Some of the techniques might introduce unfamiliar...
5
by: jrod11 | last post by:
hi, I found a jquery html table sorting code i have implemented. I am trying to figure out how to edit how many colums there are, but every time i remove code that I think controls how many colums...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.