Advertisement
Guest User

Inserção/Busca

a guest
Oct 31st, 2014
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.83 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];
  21. }
  22.  
  23.  
  24. int Busca(Aluno L[],int *tamVet,Aluno x,int *PosIns){
  25.     int inf,sup,m;
  26.     inf = 0;
  27.     sup = (*tamVet - 1);
  28.     printf("%d\n%d\n",inf,sup);
  29.     while(inf<=sup){
  30.         m = ((inf + sup)/2);
  31.         if(L[m].matricula == x.matricula){
  32.             return m;
  33.         }
  34.         else if(L[m].matricula > x.matricula){
  35.             inf = (m+1);
  36.         }
  37.         else{
  38.             m = (m-1); 
  39.         }
  40.     }
  41.     *PosIns = inf;
  42.     return 0;
  43. }
  44.  
  45. void InserePosicao(Aluno *L[],int *n,Aluno x,int PosIns){
  46.     int j;
  47.     for(j=n;j>=PosIns;j--){
  48.         L[j+1] = L[j];
  49.     }
  50.     *L[PosIns] = x;
  51.     n++;       
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement