Advertisement
Guest User

gz

a guest
Nov 21st, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. typedef struct _cvor *Position;
  5.  
  6. void DodajUListu(Position head, int x);
  7. void IspisiListu(Position head);
  8.  
  9. typedef struct _cvor
  10. {
  11. int el;
  12. Position next;
  13.  
  14. }cvor;
  15.  
  16.  
  17.  
  18.  
  19.  
  20. int main()
  21. {
  22. int broj = 5;
  23. int broj2 = 2;
  24. int broj3 = 4;
  25. Position head = NULL;
  26. head = (Position)malloc(sizeof(Position));
  27. head->next = head;
  28. DodajUListu(head,broj);
  29. DodajUListu(head, broj2);
  30. DodajUListu(head, broj3);
  31. IspisiListu(head);
  32.  
  33.  
  34. return 0;
  35. }
  36.  
  37. void DodajUListu(Position head,int x)
  38. {
  39. Position g;
  40. Position temp;
  41. temp = head;
  42. g = (Position)malloc(sizeof(cvor));
  43. while (temp->next!=head)
  44. {
  45. temp = temp->next;
  46. }
  47. g->next = temp->next;
  48. temp->next = g;
  49. g->el = x;
  50. }
  51.  
  52. void IspisiListu(Position head)
  53. {
  54. Position temp = head;
  55. while (head->next != temp)
  56. {
  57. head = head->next;
  58. printf("%d ", head->el);
  59. }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement