#include <iostream>
#include <cstdlib>
#include <time.h>
using namespace std;
void quicksort(int a[], int low, int high);
int partition(int a[], int low, int high);
int main(){
srand(time(NULL));
int n=100, a=100, b=200;
int arreglo[n];
for(int i=0; i<n; i++){
arreglo[i] = a+rand()%(b-a+1);
cout<<arreglo[i]<<" ";
}
cout<<endl<<endl<<"Arreglo ordenado"<<endl;
quicksort(arreglo, 0, 99);
for(int i=0; i<n; i++){
cout << arreglo[i] << " ";
}
cout<<endl<<endl<<"Matriz"<<endl;
int contador=25;
for(int i=0; i<10; i++){
for(int j=0; j<10; j++){
if(i>=5 && j>=5){
cout<<""<<arreglo[n-contador]<<"\t ";
contador--;
}else{
cout<<"0\t ";
}
}
cout<<endl;
}
return 0;
}
void quicksort(int arr[], int lowIndex, int highIndex){
if (lowIndex < highIndex){
int pivotIndex = partition(arr, lowIndex, highIndex);
quicksort(arr, lowIndex, pivotIndex-1);
quicksort(arr, pivotIndex+1, highIndex);
}
}
int partition(int arr[], int i, int j){
int pivot = arr[i];
int pivotIndexAux = i;
for (int k=i+1; k<=j; k++){
if (arr[k] < pivot){
pivotIndexAux++;
swap(arr[k], arr[pivotIndexAux]);
}
}
swap(arr[i], arr[pivotIndexAux]);
return pivotIndexAux;
}