I make my own insertion-sort algorithm and I put a progress bar to print in the screen the progress of sort for big numbers.
Can anyone help me to optimize my progress bar. Actually it print in the screen the progress (5% - 10% - 20% ...), but I would like to print one progressive bar like this (with actualize one unique progress bar):
[__________]
[|._________]
[|.|.________]
[|.|.|._______]
#include <cstdio>
#include <cstdlib>
#include <iostream>
usingnamespace std;
constint TAMANHO = 100000;
int insertionSort(int a[], int tam)
{
for (int j = 1 ; j < tam ; j++)
{
int chave = a[j];
int i = j - 1;
while (i >= 0 && a[i] > chave)
{
a[i+1] = a[i];
i = i - 1;
}
a[i+1] = chave;
// Status de Progresso
int progresso;
int rep;
progresso = j * 100 / TAMANHO;
if (progresso % 5 == 0 && rep != progresso)
{
cout << progresso << " | ";
rep = progresso;
}
}
}
int main(int NumberofArgs, char* pszArgs[])
{
cout << "ALGORITMO INSERTION-SORT\n\n";
int a[TAMANHO];
int i;
for (i = 0 ; i <= TAMANHO ; i++)
{
a[i] = rand() % TAMANHO;
}
cout << "Lista nao ordenada\n";
for (int x = 0 ; x < i ; x++) {
cout << a[x] << "\n";
}
insertionSort(a,i);
cout << "\nLista ordenada\n";
for (int x = 0 ; x < i ; x++) {
cout << a[x] << "\n";
}
// wait until user is ready before terminating program
// to alow the user to see the program results
system("PAUSE");
return 0;
}