Автор: Luxury31 (21.12.2008 в 21:56)
сможещь помочь в этой задаче тоже нужны счетчики такие же как и в первой?Вот код:
#include <iostream>
#include <algorithm>
#include <conio.h>
using namespace std;
const size_t MAX = 5;
void printArray(int arr[])
{
for(size_t i = 0; i < MAX; ++i)
{
cout << arr[i] << endl;
}
}
void bubbleSort(int arr[])
{
size_t i, j;
for(i = 1; i < MAX; ++i)
for(j = 0; j < MAX - i; ++j)
if (arr[j] > arr[j+1])
{
swap(arr[j], arr[j+1]);
}
}
int main()
{
int arr[MAX];
for (size_t i = 0; i < MAX; ++i)
{
cout << "Vvedite element: " << endl;
cin >> arr[i];
}
printArray(arr);
bubbleSort(arr);
cout << "Posle sortirovki: " << endl;
printArray(arr);
getch ();
return 0;
} |