Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <locale.h>
- #include <stdlib.h>
- #include <stdio.h>
- using namespace std;
- int menu();
- void deletar();
- void inclusao();
- void buscaBinaria();
- void buscaSequencial();
- int main(){
- setlocale(0,"Portuguese");
- menu();
- system("pause");
- }
- int menu(){
- system("COLOR 1F");
- //Variaveis do Menu
- double opcao;
- //Menu
- cout << "\n\t\tBusca Sequencial - Busca Binária - Inclusão - Deletar\n";
- cout << "\n\t0 - Sair";
- cout << "\n\t1 - Busca Sequencial";
- cout << "\n\t2 - Busca Binária";
- cout << "\n\t3 - Inclusão de Arquivos";
- cout << "\n\t4 - Deletando Arquivos" << endl;
- cout << "\nInforme a Opção: "; cin >> opcao;
- //Chamar o menu
- if(opcao == 0){
- return -1;
- }else if(opcao == 1){
- buscaSequencial();
- }else if(opcao == 2){
- buscaBinaria();
- }else if (opcao == 3){
- inclusao();
- }else if(opcao == 4)
- deletar();
- else
- cout << "\n>>>>>>>>>> Opção Inválida. Tente Novamente.." << endl; system("pause"); system("cls"); menu();
- return 0;
- }
- void deletar(){
- system("cls");
- const int tamanhoVetorS = 10;
- const int tamanhoVetorT = 6;
- const int tamanhoVetorA = tamanhoVetorS - tamanhoVetorT;
- int S[tamanhoVetorS] = {0,2,4,6,8,10,12,14,20,22};
- int T[tamanhoVetorT] = {4,6,8,10,12,20};
- int A[tamanhoVetorA];
- int i = 0;
- int j = 0;
- int z = 0;
- while(j < tamanhoVetorT){
- if(S[i] != T[j]){
- A[z] = S[i];
- z++;
- }else{
- j++;
- }
- i++;
- }
- while(i < tamanhoVetorS){
- A[z] = S[i];
- i++;
- j++;
- }
- cout << "\n>>>>> Impressão do Vetor S";
- for (i=0; i<tamanhoVetorS;i++){
- cout << "\nPosição [" << i+1 << "]: "<< S[i];
- }
- cout << "\n\n\n>>>>> Impressão do Vetor T";
- for (i=0; i<tamanhoVetorT;i++){
- cout << "\nPosição [" << i+1 << "]: "<< T[i];
- }
- cout << "\n\n\n>>>>> Impressão do Vetor A";
- for(i=0; i<tamanhoVetorA; i++){
- cout << "\nPosição [" << i+1 << "]: "<< A[i];
- }
- cout << endl << endl;
- }
- void inclusao(){
- system("cls");
- const int vetorS = 4;
- const int vetorT = 2;
- const int vetorA = vetorS + vetorT;
- int S[vetorS] = {1,4,9,10};
- int T[vetorT] = {2,5};
- int A[vetorA];
- int i = 0;
- int j = 0;
- int z = 0;
- while(j<vetorT){
- if(S[i] < T[j]){
- A[z] = S[i];
- i++;
- }else{
- A[z] = T[j];
- j++;
- }
- z++;
- }
- while(i<vetorS){
- A[z] = S[i];
- i++;
- z++;
- }
- cout << "\n\n\n>>>>> Impressão do Vetor A";
- for(i=0; i<vetorA; i++){
- cout << "\nPosição [" << i+1 << "]: "<< A[i];
- }
- cout << endl << endl;
- }
- void buscaBinaria(){
- system("cls");
- //Tamanho do Vetor
- const int tamanhoVetor = 10;
- //Definição do Vetor
- int vetor[tamanhoVetor] = {0,1,4,5,6,7,8,9,10,14};
- //Declaração das demais Variáveis
- int chave;
- int i = 0; //Indice do vetor
- int inicio = 0;
- int fim = tamanhoVetor-1;
- int meio;
- cout << "\nImpressão do Vetor" << endl << endl;
- for(i; i<tamanhoVetor;i++){cout << "Posição [" << i << "] " << vetor[i] << endl;}
- cout << "\nInforme a Chave a ser Buscada: "; cin >> chave;
- while(inicio <= fim){
- meio = (inicio + fim) / 2;
- if(chave > vetor[meio]){
- inicio = meio+1;
- }else{
- fim = meio-1;
- }
- }
- if(chave == vetor[meio]){
- cout << "\nChave Encontrada na Posição " << meio << endl;
- }else{
- cout << "\nChave Não Encontrada!" << endl;
- }
- }
- void buscaSequencial(){
- system("cls");
- const int tamanhoVetor = 4;
- int vetor[tamanhoVetor] = {1,3,5,7};
- int k;
- int i;
- cout << "\nInforme a Chave: "; cin >> k;
- cout << "\nChave a ser buscada [" << k << "]" << endl;
- for(i=0; i<tamanhoVetor; i++){
- cout << "Posição ["<< i << "]: " << vetor[i] << endl;
- }
- for(i=0; vetor[i] != k && k > vetor[i]; i++);
- if(vetor[i] == k)
- cout << "\nChave encontrada! Posição: " << i << endl << endl;
- else
- cout << "\nChave não encontrada!" << endl << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement