Chat LIVE With Programming Experts! There Are 23 Online Right Now...

 

Code Snippets

  

C++ Source Code


Welcome to Dream.In.Code
Become a C++ Expert!

Join 244,216 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,456 people online right now. Registration is fast and FREE... Join Now!





Bubble Sort Algorithm

Uses bubble sort to sort a vector

Submitted By: gabehabe
Actions:
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


  1. /***************************/
  2. /** BUBBLE SORT ALGORITHM **/
  3. /**   BY DANNY BATTISON   **/
  4. /**  gabehabe@hotmail.com **/
  5. /***************************/
  6.  
  7. #include <algorithm>
  8.  
  9. template <typename Iterator>
  10. void BubbleSort(Iterator beg, Iterator end)
  11. {
  12.     Iterator i, j;
  13.     for (i = beg; i != end; ++i)
  14.         for (j = beg; j < i; ++j)
  15.             if (*i < *j)
  16.                 std::iter_swap(i, j);
  17. }

Copy & Paste


Comments


There are currently no comments for this snippet. Be the first to comment!

Add comment


You must be registered and logged on to </dream.in.code> to leave comments.





Live C++ Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month