1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
|
#include <iostream>
#include <Windows.h>
#include <algorithm>
#include <vector>
using namespace std;
#define MAX 100000
void inputArray(int x[], int m);
void printArray(int x[], int m);
void sortAccessing(int x[], int m);
void sortDescendin(int x[], int m);
int main ()
{
int n ;
cout<<"Enter the size of the array: ";
cin>>n;
int myArray[MAX];
inputArray(myArray, n);
printArray(myArray, n);
sortAccessing(myArray, n);
sortDescendin(myArray, n);
cin.get(); cin.get();
return 0;
}
void inputArray(int x[], int m) {
for (int i = 0; i < m; i++) {
cout<<"Enter member in the array with index: "<<i<<" ";
cin>>x[i];
}
}
void printArray(int x[], int m) {
cout<<"\n\nMemebers of the array: "<<endl;
for(int i = 0; i < m; i++) {
cout<<" "<<x[i];
}
}
void sortAccessing(int x[], int m) {
sort(x, x+m);
cout<<"\n\nMembers of the array in acc. order: "<<endl;
for(int i = 0; i < m; i++) {
cout<<" "<<x[i];
}
}
void sortDescendin(int x[], int m){
cout<<"\n\nMembers of the array in descending order: "<<endl;
vector<int> myVector(x, x+m);
vector<int>::iterator it;
sort(myVector.begin(), myVector.end(), greater<int>());
for(it = myVector.begin(); it != myVector.end(); it++) {
cout<<" "<<*it;
}
}
| |