Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<time.h>
- #define MAX 1000
- using namespace std;
- int vetor[MAX];
- inline void iniciar(void)
- {
- for ( int i = 0 ; i < MAX ; i++)
- {
- vetor[MAX];
- }
- return;
- }
- void Adicionar(void)
- {
- bool cond;
- cond = false;
- do
- {
- int p,v;
- cout << "Informe a posicao eo valor: ";
- cin >> p >> v;
- if( ( p < 0 ) || ( p > MAX ) )
- {
- cout << "Posicao invalida tente novamente\n";
- cond = true;
- }
- else
- {
- vetor[p] = v;
- }
- }while(cond);
- return;
- }
- void Remover(void)
- {
- int v;
- cout << "Informe o valor que deseja remover: ";
- cin >> v;
- for(int i = 0 ; i < MAX ; i++)
- {
- if(vetor[i] == v)
- {
- vetor[i] = 0;
- break;
- }
- else if( ( vetor[i] = 0 ) && ( ( v > -1 ) && ( v < MAX ) ) )
- {
- char opc;
- cout << "Hum.. o valor informado nao esta contido no vetor, mas o valor e uma posicao valida"
- << "\nQuer remover o valor " << vetor[v]
- << "[S]im/[N]ao: ";
- cin >> opc;
- if ((opc == 's') || (opc == 'S'))
- {
- vetor[v] = 0;
- return;
- }
- else return;
- }
- }
- }
- void Exibir(void)
- {
- for( int i = 0; i < MAX ; i++)
- {
- if(vetor[i]) cout << vetor[i] << "\t|";
- }
- }
- void Aleatorio(void)
- {
- time(NULL);
- for (int i = 0; i < MAX ; i++)
- {
- vetor[i] = rand() % MAX;
- }
- return;
- }
- void Ordena(void)
- {
- for( int i = 0 ; i < MAX ; i++)
- {
- for(int j = 0; j < MAX; j++)
- {
- int aux = vetor[j + 1];
- if(aux < vetor[j])
- {
- vetor[j + 1] = vetor[j];
- vetor[j] = aux;
- }
- }
- }
- return;
- }
- int main()
- {
- if(MAX > 32766)
- {
- cout << "Redefina MAX para um valor menor ";
- return 0;
- }
- else iniciar();
- do
- {
- int opc;
- cout << "\nOque deseja fazer: "
- <<"\n1- Adicionar um valor\n2 - Exibir\n3 - Zerar\n4 - Ordenar\n5 - Aleatorio\n6 - Sair\n\tDigite: ";
- cin >> opc;
- switch(opc)
- {
- case 1: Adicionar(); break;
- case 2: Exibir(); break;
- case 3: Remover(); break;
- case 4: Ordena(); break;
- case 5: Aleatorio(); break;
- case 6: return 0;
- default : cout << "\nOpcao invalida\n";
- }
- }while(true);
- return -1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement