Computing.Net > Forums > Programming > BUBBLE sort in array of Structures

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

BUBBLE sort in array of Structures

Reply to Message Icon

Name: cybercellz
Date: November 16, 2003 at 23:22:39 Pacific
OS: windows 98
CPU/Ram: 233/128Mb
Comment:

I am having problems doing an alphabetical
sort on names in an array of structures (List) each of which contains a name and a number e.g.:

struct record{
char studName[50];
int studMark;
};

struct record list[7];

(The data is read into the above structure
from a .txt file in this format:

John 87
Mary 20
Rob 78
etc.etc.

Regards




Sponsored Link
Ads by Google

Response Number 1
Name: borelli35
Date: November 17, 2003 at 00:26:54 Pacific
Reply:

See posting 7407.

And it works here too!....

borelli35


0

Response Number 2
Name: saddam
Date: November 17, 2003 at 15:39:15 Pacific
Reply:

Use this algorithm:

void bubbleSort(int item[], int size)
{
int swaps, temp, right, left;
do
{
swaps = 0;
left = 0;
right = 1;
while(right<size)
{
if(item[right] < item[left]
{
temp = item[left];
item[left] = item[right];
item[right] = temp;
swaps++;
}
left++;
right++;
}
} while(swaps > 0);
}

not sure if you would like to implement as a function or in main function. replace item with your array: studName



0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


Linked list Site Sub Directories Tree



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: BUBBLE sort in array of Structures

sorting an array of string in java www.computing.net/answers/programming/sorting-an-array-of-string-in-java/18011.html

Array of Structures www.computing.net/answers/programming/array-of-structures/6344.html

cannot Sort String Array in JAVA www.computing.net/answers/programming/cannot-sort-string-array-in-java-/8805.html