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

Converting an Int sorter (code provided) into a string sorter

Ok I'm having problems just figuring out how to convert this Sorter
Expand|Select|Wrap|Line Numbers
  1. void BubbleSort (int list[], int length)
  2. {
  3.       int temp;
  4.       int counter;
  5.       int index;
  6.  
  7.       for (counter = 0; counter < length – 1; counter++)                  
  8.       {  // make one pass through the array
  9.  
  10.             for (index = 0; index < length – 1 – counter; index++)  
  11.                // compare side-by-side elements
  12.                  if (list [index] > list [index+1])    
  13.                  {                                 
  14.                        temp = list [index];               
  15.                        list [index] = list [index+1];             
  16.                        list [index+1] = temp;
  17.                   }
  18.       }     //  end of outer loop to make one pass through the array
  19. }   
  20.  
into a string sorter. My main problem is that the strings are inside a structure
Expand|Select|Wrap|Line Numbers
  1. struct Census
  2. {
  3.        string name;
  4.        int cen80;
  5.        int cen90;
  6. };
So I'm kind of leary on how to sort the name variable from an array of this structure. I also Have to use this sort, it's for a homework assignment so thx for help in advance
Oct 30 '06 #1
2 1445
Just access the structs' strings and compare those:
if (list[index].name > list[index+1].name) ...
Oct 31 '06 #2
hmm that seems like it would work but I need to know how to pass the arrayed structure to the function itself
Oct 31 '06 #3

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

Similar topics

25
by: TK | last post by:
I'm used to programming in c or c++ in which my problem is simple. I want to be able to enter a value on a page (like 3.2), and then read it as a 32-bit float and break it into it's individual...
9
by: Terry | last post by:
I am converting (attempting) some vb6 code that makes vast use of interfaces. One of the major uses is to be able to split out Read-only access to an obect. Let me give you a simple (contrived)...
1
by: Kevin S Gallagher | last post by:
I found this code (pretty sure it was from a MVP) for converting a string variable to a form object which works fine within a form. Take the code and place it into a code module and it fails on the...
3
by: ITAutobot25 | last post by:
Now this is really the last problem (for real now) with this assignment. My sorter is not working. I managed to sort by product name in my previous assignment; however, I can't get it to work on this...
1
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...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...

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.