Advertisement
6_2008-2009 OLE/ COM/ DCOM/ Active-X #215608

Bubble sort

An implementation of bubble sort alghoritem.

AI

AI 摘要: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

源代码
original-source
<pre>#include <iostream>
using namespace std;
void PrintArray(int[], int);
void BubbleSort(int[], int);
void Swap(int&, int&);
int main(int argc, char** argv){
  int const arraySize = 8;
  int ourArray[arraySize] = {657,56,4,93,5646,767,5,96};
  //array before sorting
  PrintArray(ourArray, arraySize);
  //sort array
  BubbleSort(ourArray, arraySize);
  //array before after
  PrintArray(ourArray, arraySize);
	return 0;
}
void PrintArray(int array[], int arraySize){
  for (int i=0; i < arraySize; i++){
    cout << array[i] << " ";
  }
  cout << endl;
}
void BubbleSort(int array[], int arraySize){
  bool swaped=true;
  do{
    swaped = false;
    for (int i=0; i < (int)sizeof(array); i++){
      if(array[i] > array[i+1]){
        Swap(array[i], array[i+1]);
        swaped = true;
      }
    }
  }while(swaped);
}
void Swap(int& first, int& second){
  int tmp = first;
  first = second;
  second = tmp;
}
</pre>
原始评论 (3)
从 Wayback Machine 恢复