Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- typedef struct vetor Vetor;
- struct vetor{
- int * numeros;
- int tamanho;
- int tamanho_maximo;
- };
- Vetor * vetor_cria (int tamanho_maximo);
- void vetor_libera(Vetor * p);
- void vetor_insere (Vetor * p, int numero);
- void vetor_remove (Vetor * p, int numero);
- int vetor_obtem_minimo (Vetor * p);
- int vetor_obtem_tamanho (Vetor * p);
- int main(){
- int i, n, j, num;
- scanf("%d",&n);
- Vetor * p = vetor_cria(n);
- char c;
- scanf("%c",&c);
- while(c != 'F'){
- if(c == 'I'){
- scanf("%d",&num);
- vetor_insere(p,num);
- }
- if(c == 'M'){
- printf("%d\n",vetor_obtem_minimo(p));
- }
- if(c == 'R'){
- scanf("%d",&num);
- vetor_remove(p,num);
- }
- scanf("%c",&c);
- }
- }
- Vetor * vetor_cria (int tamanho_maximo){
- Vetor * v = (Vetor *) malloc(sizeof(Vetor));
- if(v != NULL){
- v->numeros = (int *) malloc(sizeof(int)*tamanho_maximo);
- v->tamanho = 0;
- v->tamanho_maximo = tamanho_maximo;
- }
- return v;
- }
- void vetor_libera(Vetor * p){
- free(p->numeros);
- free(p);
- }
- void vetor_insere (Vetor * p, int numero){
- if(p->tamanho != p->tamanho_maximo){
- p->numeros[p->tamanho] = numero;
- p->tamanho++;
- }
- }
- void vetor_remove (Vetor * p, int numero){
- if(p->tamanho != 0){
- int i,j;
- for(i = 0; i < p->tamanho; i++){
- if(p->numeros[i] == numero){
- for(j = i; j < p->tamanho-1; j++){
- p->numeros[j] = p->numeros[j+1];
- }
- i--;
- p->tamanho--;
- }
- }
- }
- }
- int vetor_obtem_minimo (Vetor * p){
- if(p->tamanho == 0){
- return -1;
- }
- int min = p->numeros[0],i;
- for(i = 1; i < vetor_obtem_tamanho(p); i++){
- if(min > p->numeros[i]){
- min = p->numeros[i];
- }
- }
- return min;
- }
- int vetor_obtem_tamanho (Vetor * p){
- return p->tamanho;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement