What's Here?
- Members: 137,220
- Replies: 481,459
- Topics: 75,056
- Snippets: 2,567
- Tutorials: 675
- Total Online: 2,238
- Members: 105
- Guests: 2,133
|
This is a snippet that will perform a BubbleSort on a string (char) array
|
Submitted By: PsychoCoder
|
|
|
Rating:
|
|
Views: 218 |
Language: C++
|
|
Last Modified: August 7, 2008 |
Snippet
#include <iostream>
#include <conio.h>
#include <cstring>
using namespace std;
void PerformBubbleSort(const char *strArray[] , int arraySize)
{
int compare;
//loop throgh the size of the array
for (int i = 0; i < arraySize - 1 ;++i)
{
//loop through each word in the array
for (int j = 0; j < arraySize - 1 - i; ++j)
{
//compare the first character to see if they match
compare = strcmp (strArray[j], strArray[j+1]);
//check the value of the comparison
if (compare > 0)
{
//they do not match so call swap to arrange the current list
swap (strArray[j] , strArray[j+1]);
}
}
}
}
Copy & Paste
|
|
|
Reference Sheets
Bye Bye Ads
Monthly Drawing
Top Contributors
Top 10 Kudos This Month
|