Advertisement
Guest User

Untitled

a guest
May 26th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1. //Bez glowy
  2. struct element
  3. {
  4. int i;
  5. struct element * next;
  6. };
  7.  
  8. struct element * utworz()
  9. {
  10. struct element * wskaznik = malloc(sizeof(struct element));
  11. wskaznik->next=NULL;
  12. return wskaznik;
  13. };
  14.  
  15. void dodaj(struct element*Lista, int a)
  16. {
  17. struct element * wsk = malloc(sizeof(struct element));
  18. wsk->i=a;
  19. wsk->next=Lista->next;
  20. Lista->next=wsk;
  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. int main()
  39. {
  40.  
  41. struct element* l1 = utworz();
  42. struct element* l2 = utworz();
  43. dodaj(l1,1);
  44. dodaj(l1,1);
  45. dodaj(l1,1);
  46. dodaj(l2,1);
  47. dodaj(l2,1);
  48. dodaj(l2,1);
  49. printf("%i",porownaj(l1,l2));
  50. return 0;
  51. }
  52.  
  53. struct element*znajdz(struct element*Lista, int a)
  54. {
  55. while((Lista!=NULL)&&(Lista->i!=a))
  56. {
  57. Lista=Lista->next;
  58. }
  59. return Lista;
  60. };
  61. void wyczysc(struct element *Lista)
  62. {
  63. struct element * wsk=Lista;
  64. while(Lista!=NULL)
  65. {
  66. Lista=Lista->next;
  67. free(wsk);
  68. wsk=Lista;
  69. }
  70. }
  71. struct element * usun(struct element* Lista, int a)
  72. {
  73. struct element * wsk,*wsk2;
  74. if(Lista=NULL)
  75. return Lista;
  76. wsk=Lista;
  77. if(Lista->i==a)
  78. {
  79. Lista=Lista->next;
  80. free(wsk);
  81. }
  82. else{
  83. while((wsk->next!=NULL)&&(wsk->next->i!=a))
  84. wsk=wsk->next;
  85. wsk->next=wsk2->next;
  86. free(wsk2);
  87. }
  88. return Lista;
  89. };
  90. int minimum(struct element*Lista)
  91. {
  92. int min=Lista->i;
  93. while(Lista!=NULL)
  94. {
  95. if(Lista->i<min)
  96. min=Lista->i;
  97. Lista=Lista->next;
  98. }
  99. return min;
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement