Advertisement
Guest User

Untitled

a guest
May 26th, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. // Z glowa
  2. struct element
  3. {
  4. int i;
  5. struct element * next;
  6. };
  7.  
  8. void dodaj(struct element*Lista, int a)
  9. {
  10. struct element * wsk = malloc(sizeof(struct element));
  11. wsk->i=a;
  12. wsk->next=Lista->next;
  13. Lista->next=wsk;
  14. };
  15.  
  16. struct element * utworz()
  17. {
  18. struct element * wskaznik = malloc(sizeof(struct element));
  19. wskaznik->next=NULL;
  20. return wskaznik;
  21. };
  22.  
  23. int porownaj(struct element *Lista, struct element *Lista2)
  24. {
  25. int isSame = 1;
  26. while(Lista->next != NULL && Lista2->next != NULL)
  27. {
  28. Lista = Lista->next;
  29. Lista2 = Lista2->next;
  30. if(Lista->i != Lista2->i)
  31. {
  32. isSame = 0;
  33. break;
  34. }
  35. }
  36. return isSame;
  37. }
  38.  
  39. int main()
  40. {
  41. struct element* l1 = utworz();
  42. dodaj(l1,2);
  43. struct element* l2 = utworz();
  44. dodaj(l2,3);
  45.  
  46. printf("%i",porownaj(l1,l2));
  47. return 0;
  48. }
  49. void wyczysc(struct element * Lista)
  50. {
  51. struct element * wsk=Lista->next;
  52. Lista=wsk;
  53. while(Lista!=NULL)
  54. {
  55. Lista=Lista->next;
  56. free(wsk);
  57. wsk=Lista;
  58. }
  59. }
  60. struct element * znajdz(struct element* Lista,int a)
  61. {
  62. Lista=Lista->next;
  63. while((Lista!=NULL)&&(Lista->i!=a))
  64. Lista=Lista->next;
  65. return Lista;
  66. };
  67. void usun(struct element* Lista,int a)
  68. {
  69. struct element * wsk;
  70. while((Lista->next!=NULL)&&(Lista->next->i!=a))
  71. Lista=Lista->next;
  72. if(Lista->next!=NULL)
  73. {
  74. wsk=Lista->next;
  75. Lista->next=wsk->next;
  76. free(wsk);
  77. }
  78. }
  79. int minimum(struct element* Lista)
  80. {
  81. int min=Lista->next->i;
  82. while(Lista->next!=NULL)
  83. {
  84. Lista=Lista->next;
  85. if(Lista->i<min)
  86. min=Lista->i;
  87. }
  88. return min;
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement