473,396 Members | 2,050 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,396 software developers and data experts.

Alphabetically sorting

My program displays the unsorted list of names in the array. How do i display these names in alphabetical order also.

Here is my code.

#include <iostream>
using namespace std;

const int numNames = 10;
const int nameSize = 17;

void showArray(char [][nameSize],char);
void selectionSort(int [][nameSize], int);

int main()
{

char names [numNames][nameSize]=
{"Collins,Bill",
"Smith,Bart",
"Allen,Jim",
"Griffin,Jim",
"Stamey,Marty",
"Rose,Geri",
"Taylor,Terri",
"Johnson,Jill",
"Allison,Jeff",
"Looney,Joe"};

showArray(names,numNames);

}
void showArray(char array [][nameSize], char size)
{
for(int counter = 0; counter < size; counter++)
{
cout << array[counter] << endl;
}
}

void selectionSort(char array[][nameSize],int size)
{
int counter, minRow;
char minValue[17];

for(counter = 0; counter < (size - 1); counter++)
minRow = counter;
strcpy(minValue,array[counter]);

for(int index = counter+1; index < size; index++)
{ if(strcmp(array[index],minValue)<0)
strcpy(minValue,array[index]);
minRow = index;
}
}

The output is

Collins,Bill
Smith,Bart
Allen,Jim
Griffin,Jim
Stamey,Marty
Rose,Geri
Taylor,Terri
Johnson,Jill
Allison,Jeff
Looney,Joe


My question is how do i sort them alphabetically also.
Nov 17 '06 #1
1 5983
Ganon11
3,652 Expert 2GB
Use a sort method - these can be found on the internet pretty easily. It looks like you already have a function prototype called selectionSort - just fill in the function definition, sort the list, and print again.
Nov 17 '06 #2

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

Similar topics

9
by: lawrence | last post by:
Is there an easy way to sort a 2 dimensional array alphabetically by the second field in each row? Also, when I use sort() on a two dimensional array, it seems to work a lot like...
3
by: A.T. | last post by:
Am trying to sort the following file with the <xsl:sort> function, but can't get it to work properly. Would like the id column sorted according both alphabetically & numerically. (e.g. A-01, A-02,...
2
by: simon | last post by:
I have column of dataType varchar(10). The values in this column are decimal numbers, 'NUL', OR ''. (because of 'NUL' and '' values I haven't defined column as decimal(18,2)) When I fill...
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....
3
by: ivijayan | last post by:
Hi Everybody Is there a way when one can sort data in a report according to one's choice and not ascending or descending alphabets or numbers? e.g., The sorting should be done in the following...
0
by: Martin H. | last post by:
Hi, I've got this problem with an enumeration of a property of a UserControl. The following code shows the problem: Public Enum TestEnum As Integer Arthur = 0 Zachary = -1 End Enum
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...
7
by: Totti | last post by:
Hi all, I am a newbie to javascript learning it for 2 months now, i am trying to make a sorter who will read english words from the one tex area or data file and show the result in the 2nd text...
5
by: kylie991 | last post by:
I'm confused as to why this isnt working.. am i doing this right?? I have to create a function that does the following: - Insert a word to the linked list so that the list // ...
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: 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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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.