What's Here?
- Members: 244,216
- Replies: 692,972
- Topics: 113,135
- Snippets: 3,863
- Tutorials: 935
- Total Online: 1,456
- Members: 87
- Guests: 1,369
|
Uses bubble sort to sort a vector
|
Submitted By: gabehabe
|
|
Rating:
 
|
|
Views: 3,181 |
Language: C++
|
|
Last Modified: May 22, 2008 |
Instructions: Create a vector, and pass the beginning and end, like so:
bubbleSort (myVector.begin(), myVector.end()); |
Snippet
/***************************/
/** BUBBLE SORT ALGORITHM **/
/** BY DANNY BATTISON **/
/** gabehabe@hotmail.com **/
/***************************/
#include <algorithm>
template <typename Iterator>
void BubbleSort(Iterator beg, Iterator end)
{
Iterator i, j;
for (i = beg; i != end; ++i)
for (j = beg; j < i; ++j)
if (*i < *j)
std::iter_swap(i, j);
}
Copy & Paste
|
|
|
Be Social
Reference Sheets
Bye Bye Ads
Monthly Drawing
Top Contributors
Top 10 Kudos This Month
|