Advertisement
Guest User

Untitled

a guest
Oct 13th, 2015
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. struct nodo{
  5. int dato;
  6. struct nodo*siguiente;
  7. };
  8.  
  9. void agregar(struct nodo**ultimo,struct nodo*primero){
  10. int a;
  11. if((*ultimo)==NULL){
  12. primero=ultimo;
  13. (*ultimo)=malloc(sizeof(struct nodo));
  14. printf("Ingrese el dato a agregar\n");
  15. scanf("%d",&a);
  16. (*ultimo)->dato=a;
  17. (*ultimo)->siguiente=NULL;
  18. system("pause");
  19. }
  20. else{
  21. struct nodo*temporal=malloc(sizeof(struct nodo));
  22. (*ultimo)->siguiente=malloc(sizeof(struct nodo));
  23. temporal=(*ultimo)->siguiente;
  24. ultimo=temporal;
  25. printf("Ingrese el dato a agregar\n");
  26. scanf("%d",&a);
  27. (*ultimo)->dato=a;
  28. system("pause");
  29. }
  30. }
  31. void buscar(struct nodo*ultimo,struct nodo*primero){
  32. int b,aux;
  33. struct nodo*auxi;
  34. printf("Ingrese el dato a buscar\n");
  35. scanf("%d",&b);
  36. if(ultimo==NULL){
  37. printf("La lista esta vacia\n");
  38. system("pause");
  39. return;}
  40. else
  41. for(auxi=primero;auxi==NULL;auxi=auxi->siguiente){
  42. //auxi->siguiente=malloc(sizeof(struct nodo));
  43. if(auxi->dato==b)
  44. aux++;
  45. printf("a\n");
  46. }
  47. if(aux==0)
  48. printf("el dato no esta en la lista\n");
  49. else
  50. printf("el dato esta en la lista");
  51. system("pause");
  52. }
  53.  
  54.  
  55. void mostrar(struct nodo*ultimo,struct nodo*primero){}
  56.  
  57.  
  58. int main()
  59. {
  60. struct nodo *ultimo=NULL;
  61. struct nodo *primero=NULL;
  62. int op;
  63. while(1){
  64. system("cls");
  65. printf("1-Agregar nro\n2-Mostrar\n3-Buscar\n4-Salir\nIngresar opcion:");
  66. scanf("%d",&op);
  67. switch(op){
  68. case 1:system("cls");
  69. agregar(&ultimo,primero);
  70. break;
  71. case 2:system("cls");
  72. mostrar(ultimo,primero);
  73. break;
  74. case 3:system("cls");
  75. buscar(ultimo,primero);
  76. break;
  77. case 4:exit(0);
  78. break;
  79. }
  80.  
  81. }
  82. return 0;
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement