Advertisement
Guest User

Untitled

a guest
Jan 20th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. struct lista
  5. {
  6. int val;
  7. struct lista *urm;
  8. };
  9.  
  10. typedef struct lista LISTA;
  11.  
  12. int main(void)
  13. {
  14. LISTA *primul, *p, *q, *aux;
  15. int i, nr;
  16.  
  17. printf("Introduceti numarul de elemnte: ");
  18. scanf("%d", &nr);
  19.  
  20. p=(LISTA*)malloc(sizeof(LISTA));
  21. if ( p == NULL)
  22. {
  23. printf("Alocare dinamica esuata!");
  24. exit(1);
  25. }
  26. printf("Tastati valoarea primului element: ");
  27. scanf("%d", &p->val);
  28. p->urm = NULL;
  29. primul = p;
  30.  
  31. for (i=1; i<nr; i++)
  32. {
  33. q = (LISTA*)malloc(sizeof(LISTA));
  34. if (q == NULL)
  35. {
  36. printf("Alocare dinamica esuata!");
  37. exit(1);
  38. }
  39.  
  40. printf("Tastati valoare elementului %d: ", i+1);
  41. scanf("%d", &q->val);
  42.  
  43. q->urm = NULL;
  44. p->urm = q;
  45. p = q;
  46.  
  47. }
  48.  
  49. for(p=primul, i=0; p != NULL; p = p->urm, i++)
  50.  
  51. //if (p->val % 2 == 0)
  52. aux = primul;
  53. if (p->val) % 2 == 0)
  54. {
  55. primul = aux->urm;
  56. free(aux);
  57. }
  58. for(p=primul, i=0; p != NULL; p = p->urm, i++)
  59. printf("%d", p->val);
  60.  
  61. for (p=primul; p != NULL; p=q)
  62. {
  63. q = p->urm;
  64. free(p);
  65. }
  66.  
  67. return 0;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement