Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //KUO_HSIANG_YU
- //https://www.facebook.com/groups/1403852566495675/permalink/2392492320965023/
- #include <iostream>
- #include <cstdlib>
- using std::cout;
- using std::cin;
- int main(int argc, char *argv[]) {
- system("color f0");
- int *array = NULL;
- int size = 0;
- int temp = 0;
- int i = 0, j = 0;
- cout << "Please enter array size: ";
- cin >> size;
- if (size < 1) {
- cout << "Error, array size can not be less than 1.\n";
- system("pause");
- return 0;
- }
- array = new int[size];
- for (i = 0; i < size; i++) {
- array[i] = 0;
- }
- for (i = 0; i < size; i++) {
- cout << (i + 1) << ". ";
- cin >> array[i];
- }
- //Using Bubble Sort to sort array.
- for (i = 0; i < (size - 1); i++) {
- for (j = (i + 1); j < size; j++) {
- if (array[i] < array[j]) {
- temp = array[i];
- array[i] = array[j];
- array[j] = temp;
- }
- }
- }
- bool isSecond = false;
- for (int i = 0; i < size; i++) {
- if (true == isSecond) {
- cout << " > ";
- }
- else {
- isSecond = true;
- }
- cout << array[i];
- }
- cout << "\n";
- cout << "\n";
- delete[] array;
- array = NULL;
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement