Answer to Question #35309 in C++ for ushanandhini

Question #35309
a C++ program to find ascending order for given numbers using class
1
Expert's answer
2013-09-24T13:26:06-0400
class Sorter
{
private:
static void Swap(int& a, int& b)
{
int tmp = a;
a = b;
b = tmp;
}

public:
static void BubbleSortAscending(int* array, int size)
{
if (!array || size <= 1)
return;

for (int g = 0; g < size - 1; g++)
for (int q = 1; q < size - g; q++)
if (array[q - 1] > array[q])
Swap(array[q - 1], array[q]);
}
};


#include <iostream>
#include <list>


using namespace std;


void print_array(int* array, int size)
{
for (int z = 0; z < size; z++)
cout << " " << array[z];
cout << endl;
}


int main()
{
list<int> numbers;
cout << "Enter some numbers (type any letter to end the sequence):" << endl << " ";

int tmp;
while (cin >> tmp)
numbers.push_back(tmp);
cout << endl;

int arraySize = numbers.size();
int* array = new int[arraySize];
copy(numbers.begin(), numbers.end(), array);

Sorter::BubbleSortAscending(array, arraySize);
cout << "The numbers entered in ascending order:" << endl;
print_array(array, arraySize);

return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS