kalo93

Untitled

Jan 18th, 2015
307
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<conio.h>
  3. #include <stdlib.h>
  4. #include <locale.h>
  5. #include <windows.h>
  6. #define MAX 200
  7. struct tipo_lista{
  8. int cod;
  9. struct tipo_lista *prox;
  10. };
  11.  
  12. struct tipo_lista *primeiro;
  13. struct tipo_lista *ultimo;
  14.  
  15. void flvazia(){
  16. struct tipo_lista *aux;
  17. aux= (struct tipo_lista*)malloc(sizeof(struct tipo_lista));
  18. primeiro=aux;
  19. ultimo=primeiro;
  20. }
  21.  
  22. int insere(int x){
  23. struct tipo_lista *aux;
  24. aux=(struct tipo_lista*)malloc(sizeof(struct tipo_lista));
  25. aux->cod=x;
  26. ultimo->prox;
  27. aux->prox=NULL;
  28. }
  29. void imprime(){
  30. struct tipo_lista *aux;
  31. aux=primeiro->prox;
  32. while(aux!=NULL){
  33. printf("item =%d", aux->cod);
  34. aux=aux->prox;
  35. }
  36. }
  37.  
  38. void pesquisa(int x){
  39. struct tipo_lista *aux;
  40. int flag=0;
  41. aux=primeiro->prox;
  42. while(aux!=NULL){
  43. if (aux->cod==x){
  44. printf("encontrou %d", x);
  45. flag=1;
  46. aux=NULL;
  47. }
  48. else
  49. aux=aux->prox;
  50. }
  51. if (flag==0)
  52. printf("item%d nao encontrou",x);
  53. }
  54. main(){
  55. char op='2';
  56. int i, codigo;
  57. flvazia();
  58. while(op!='o'){
  59. printf("codigo");
  60. scanf("%d",&codigo);
  61. insere(codigo);
  62. printf("continuar?");
  63. op = getch();
  64.  
  65. }
  66. imprime();
  67. printf("pesquisa");
  68. scanf("%d",&codigo);
  69. pesquisa(codigo);
  70. getch();
  71. }
Advertisement
Add Comment
Please, Sign In to add comment