Advertisement
Guest User

Untitled

a guest
Oct 31st, 2014
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.92 KB | None | 0 0
  1. #include<stdio.h>
  2.  
  3. typedef struct Aluno{
  4.    
  5.     int matricula;
  6.     char nome[30];
  7.     int idade;
  8.    
  9. }Aluno;
  10.  
  11. int Busca(Aluno L[],int *tamVet,Aluno x,int *PosIns);
  12. void InserePosicao(Aluno L[],int n,Aluno x,int PosIns);
  13.  
  14. int main(void)
  15. {
  16.     Aluno vetor;
  17.     int n = 0;
  18.     int PosIns = 0;
  19.     int tamVet = 10;
  20.     Aluno L[tamVet+1];
  21.     Busca(L,&tamVet,vetor,&PosIns);
  22. //  InserePosicao(L,n,vetor,&PosIns);
  23.     printf("%d",PosIns);
  24. }
  25.  
  26.  
  27. int Busca(Aluno L[],int *tamVet,Aluno x,int *PosIns){
  28.     int inf,sup,m;
  29.     inf = 0;
  30.     sup = (*tamVet - 1);
  31.     //printf("%d\n%d",inf,sup);
  32.     while(inf<=sup){
  33.         m = ((inf + sup)/2);
  34.         if(L[m].matricula == x.matricula){
  35.             return m;
  36.         }
  37.         else if(L[m].matricula < x.matricula){
  38.             inf = (m+1);
  39.         }
  40.         else{
  41.             inf = (m-1);   
  42.         }
  43.     }
  44.     *PosIns = inf;
  45.     return -1;
  46. }
  47.  
  48. void InserePosicao(Aluno L[],int n,Aluno x,int PosIns){
  49.     int j;
  50.     for(j=n;j>=PosIns;j--){
  51.         L[j+1] = L[j];
  52.     }
  53.     L[PosIns] = x;
  54.     n++;       
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement