Resonati

Untitled

Jun 24th, 2019
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.63 KB | None | 0 0
  1. struct element{
  2. int i;
  3. struct element *next;
  4. };
  5. (1)struct element * utworz(){/* tworzy wskaznik do pustej listy */
  6. return NULL;
  7. };
  8. (2)struct element * dodaj(struct element* Lista, int a){* dodaje na poczatku listy element o polu int i = a */
  9. struct element * wsk=malloc(sizeof(struct element));
  10. wsk->i=a;
  11. wsk->next=Lista;
  12. return wsk;
  13. }
  14.  
  15. (3)void wypisz(struct element * Lista){ ////wypisuje liste w jednej linii///
  16. // printf("\n");
  17. while(Lista!=NULL){
  18. printf("%d ",Lista->i);
  19.  
  20. Lista=Lista->next;
  21.  
  22. }
  23. printf("\n) }
  24. (4)void wyczysc(struct element * Lista){
  25. struct element * wsk=Lista;
  26. while(Lista!=NULL){
  27. Lista=Lista->next;
  28. free (wsk);
  29. wsk=Lista;
  30. }
  31. }
  32.  
  33.  
  34.  
  35.  
  36. (5)struct element * dodajk(struct element* Lista, int a){ **dodaje na koncu listy element o polu int i = a **
  37. struct element *wsk;
  38. if (Lista==NULL){
  39. Lista=wsk= malloc(sizeof(struct element));
  40. }
  41. else{
  42. wsk=Lista;
  43. while(wsk->next!=NULL)
  44. wsk=wsk->next;
  45. wsk->next=malloc(sizeof(struct element));
  46. wsk=wsk->next;
  47. }
  48. wsk->i=a;
  49. wsk->next=NULL;
  50. return Lista;
  51. }
  52.  
  53.  
  54. (6)struct element * dodajk1(struct element* Lista, int a){
  55. struct element *wsk,*wsk1;
  56. wsk=malloc(sizeof(struct element));
  57. wsk->i=a;
  58. wsk->next=NULL;
  59. if (Lista==NULL){Lista=wsk;
  60. return wsk;
  61. }
  62.  
  63.  
  64. wsk1=Lista;
  65. while(wsk1->next!=NULL) wsk1=wsk1->next;
  66. wsk1->next=wsk;
  67.  
  68. return Lista;
  69. }
  70.  
  71. (7)struct element * dodajw(struct element *Lista,struct element *elem, int a){
  72. struct element *wsk;
  73. wsk=malloc(sizeof(struct element));
  74. wsk->i=a;
  75. if(elem==NULL){
  76. wsk->next=Lista;
  77. Lista=wsk;
  78. }
  79. else
  80. {
  81. wsk->next=elem->next;
  82. elem ->next=wsk;
  83. }
  84.  
  85. return Lista;
  86. }
  87. (8)struct element * znajdz(struct element *Lista, int a){* zwraca adres elementu o polu int i =a
  88. lub NULL jesli nie ma na liscie takiego elementu */
  89. while((Lista!=NULL)&&(Lista->i!=a))
  90. Lista=Lista->next;
  91. return Lista;
  92. }
  93.  
  94.  
  95. (9)struct element * usun(struct element *Lista,int a){* usuwa element o polu int i =a */
  96. struct element *wsk,*wsk2;
  97. if(Lista==NULL)
  98. return Lista;
  99. wsk=Lista;
  100. if(Lista->i==a){
  101. Lista = Lista->next;
  102. free(wsk);
  103. }
  104. else{
  105. while((wsk->next!=NULL)&&(wsk->next->i!=a)) wsk=wsk->next;
  106.  
  107. if(wsk->next!=NULL){
  108. wsk2=wsk->next;
  109. wsk->next=wsk2->next;
  110. free(wsk2);
  111. }
  112. }
  113. return Lista;
  114. }
  115. (10)struct element * usun1(struct element *Lista,int a){
  116. struct element *wsk,*wsk2;
  117. if(Lista==NULL)
  118. return Lista;
  119. wsk=Lista;
  120. if(Lista->i==a){
  121. Lista = Lista->next;
  122. free(wsk);
  123. return Lista;
  124. }
  125.  
  126. while((Lista->next!=NULL)){
  127.  
  128. if(Lista->next->i==a){
  129. wsk2=Lista->next;
  130. Lista->next=wsk2->next;
  131. free(wsk2);
  132. return wsk;
  133. }
  134. Lista=Lista->next;
  135. }
  136. return wsk;
  137. }
  138.  
  139.  
  140. (11)struct element * usunniep(struct element *Lista){usuwa wszystkie o nieparzystej wartosci pola int i */
  141. struct element *wsk,*wsk2;
  142. wsk=Lista;
  143. if(Lista->i%2!=0){
  144. while(Lista!=NULL&&Lista->i%2!=0){
  145. wsk2=Lista;
  146. Lista = Lista->next;
  147. free(wsk2);
  148. if(Lista==NULL) return Lista;
  149. }
  150. }
  151. wsk=Lista;
  152.  
  153. while(Lista!=NULL){
  154. while (Lista->next!=NULL&&Lista->i%2==0&&Lista->next->i%2==0) Lista=Lista->next;
  155. if(Lista->next==NULL) return wsk;
  156.  
  157. while(Lista->next!=NULL&&Lista->next->i%2!=0){
  158. wsk2=Lista->next;
  159. Lista->next=wsk2->next;
  160. free(wsk2);
  161. if(Lista==NULL) return wsk;
  162. }
  163.  
  164. }
  165.  
  166. }
  167.  
  168.  
  169. (12)struct element * dodajrosnaco(struct element* Lista, int a){
  170. struct element *wsk,*wsk2;
  171. if (Lista==NULL){
  172. Lista = malloc(sizeof(struct element));
  173. Lista->i=a;
  174. Lista->next=NULL;
  175. return Lista;
  176. }
  177. if(Lista->i==a) return Lista;
  178. if(a<Lista->i){
  179. wsk= malloc(sizeof(struct element));
  180. wsk->i=a;
  181. wsk->next=Lista;
  182. return wsk;
  183. }
  184. wsk=Lista;
  185.  
  186. while(wsk->next!=NULL&&wsk->next->i<a) wsk=wsk->next;
  187.  
  188. if(wsk->next==NULL){
  189. wsk2= malloc(sizeof(struct element));
  190. wsk->next=wsk2;
  191. wsk2->i=a;
  192. wsk2->next=NULL;
  193. return Lista;
  194. }
  195. if(wsk->next->i==a) return Lista;
  196.  
  197. wsk2=malloc(sizeof(struct element));
  198. wsk2->i=a;
  199. wsk2->next=wsk->next;
  200. wsk->next=wsk2;
  201.  
  202. return Lista;
  203.  
  204. }
  205.  
  206. (12)void dodajprzedn(struct element *Lista){ dla listy z glową przed kazdy element
  207. o nieparzystej wartosci pola int i
  208. struct element *wsk;
  209. while (Lista->next!=NULL){
  210. if(Lista->next->i%2==1){
  211. wsk=malloc(sizeof(struct element));
  212. wsk->i=Lista->next->i+1;
  213. wsk->next=Lista->next;
  214. Lista->next=wsk;
  215. Lista=wsk->next;
  216. }else
  217. Lista=Lista->next;
  218. }
  219.  
  220. }
  221. (13)void dodajzanp(struct element *Lista){
  222. struct element *wsk;
  223. while (Lista!=NULL){
  224. if(Lista->i%2==1){
  225. wsk=malloc(sizeof(struct element));
  226. wsk->i=Lista->i+1;
  227. wsk->next=Lista->next;
  228. Lista->next=wsk;
  229. Lista=wsk->next;
  230. }else
  231. Lista=Lista->next;
  232. }
  233.  
  234. }
Add Comment
Please, Sign In to add comment