- Home
- Registration
- Database Design
- Password Keeper
- MySQL and Excel
- Learn MySQL
- Learn PHP
- Learn Visual Basic
- Learn Java
- Web Site Tips
- Miscellaneous
- C ++ Code Examples
- Start C++
- C ++ Continue
- C ++ Pointer
- Variable Scope
- Linked List
- Bubble Sort
- Two Bubble Sort
- Insertion Sort
- Selection Sort
- Two Selection Sort
- Merge Bin Sort
- Advertise here
- Site map
The bubble sort algorithm - C++ source code - Learning C++
![]()
![]()
![]()
![]()
Precondition: the function accepts an unsorted array and integer size that is the size of the array:
Post condition: Sorted array
void BubbleSort ( int
size, int array[])
{
int current = 0;
bool sorted =
false;
while (( current < size)&&(sorted = = false))
{
int walker = size-1;
sorted = true;
while (walker > current)
{
if ( array[walker] < array[walker - 1]
)
{
sorted = false;
exchange( array, walker, walker-1);
}
walker--;
}
current++;
}
}
void exchange (int array[], int a, int b)
{
int temp=array[a];
array[a]=array[b];
array[b]=temp;
}
Did you find information useful? Send to your friend a link to this page
Please rate the tutorial
| Comments |
|---|
Web programming Tips