Advertisement
Guest User

Untitled

a guest
Jan 17th, 2020
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.75 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5.  
  6. typedef struct cvor* PCVOR;
  7. typedef struct cvor {
  8. int data;
  9. PCVOR next;
  10. }CVOR;
  11.  
  12. void ubaciNaPocetak(PCVOR* head, int num);
  13. void ubaciNaKraj(PCVOR* head, int num);
  14. void izbaciSaPocetka(PCVOR* head);
  15. void izbaciSaKraja(PCVOR* head);
  16. void izbaciTrazeniBroj2(PCVOR* head, int find);
  17. void prebacivanjeNeparnih(PCVOR* head, PCVOR* neparni);
  18. void ispisiListu(PCVOR head);
  19.  
  20. int main(void) {
  21.  
  22. PCVOR new = NULL;
  23. PCVOR neparni = NULL;
  24.  
  25. ubaciNaKraj(&new, 1);
  26. ubaciNaKraj(&new, 2);
  27. ubaciNaKraj(&new, 3);
  28. ubaciNaKraj(&new, 4);
  29. ubaciNaKraj(&new, 5);
  30. ubaciNaKraj(&new, 6);
  31. ubaciNaKraj(&new, 7);
  32. ubaciNaKraj(&new, 8);
  33. ubaciNaKraj(&new, 9);
  34.  
  35. prebacivanjeNeparnih(&new, &neparni);
  36.  
  37. ispisiListu(neparni);
  38.  
  39. return 0;
  40. }
  41.  
  42. void ubaciNaPocetak(PCVOR* head, int num)
  43. {
  44. PCVOR new = malloc(sizeof(CVOR));
  45. new->data = num;
  46. new->next = *head;
  47. *head = new;
  48. }
  49. void ubaciNaKraj(PCVOR* head, int num)
  50. {
  51. if (*head == NULL) {
  52. ubaciNaPocetak(head, num);
  53. return;
  54. }
  55. PCVOR new = malloc(sizeof(CVOR));
  56. new->next = NULL;
  57. new->data = num;
  58. PCVOR pom = *head;
  59. while (pom->next != NULL) {
  60. pom = pom->next;
  61. }
  62. pom->next = new;
  63. }
  64. void izbaciSaPocetka(PCVOR* head)
  65. {
  66. if (*head == NULL) {
  67. printf("GRESKA/LISTA JE PRAZNA!\n");
  68. return;
  69. }
  70. PCVOR pom = *head;
  71. *head = pom->next;
  72. free(pom);
  73. }
  74. void izbaciSaKraja(PCVOR* head)
  75. {
  76. if (*head == NULL) {
  77. printf("GRESKA/LISTA JE PRAZNA!\n");
  78. return;
  79. }
  80. PCVOR temp = *head;
  81. PCVOR temp_next = temp->next;
  82. if (temp->next == NULL) {
  83. izbaciSaPocetka(head);
  84. return;
  85. }
  86. while (temp_next->next != NULL) {
  87. temp = temp_next;
  88. temp_next=temp_next->next;
  89. }
  90. temp->next = NULL;
  91. free(temp_next);
  92. }
  93. void izbaciTrazeniBroj(PCVOR* head, int find)
  94. {
  95. }
  96. void ispisiListu(PCVOR head)
  97. {
  98. if (head == NULL) {
  99. printf("GRESKA/LISTA JE PRAZNA!");
  100. return;
  101. }
  102. printf("Lista: ");
  103. while (head != NULL) {
  104. printf("%3d%3", head->data);
  105. head = head->next;
  106. }
  107. printf("\n");
  108. }
  109. void izbaciTrazeniBroj2(PCVOR* head, int find) {
  110. if (*head == NULL) {
  111. printf("GRESKA/LISTA JE PRAZNA!");
  112. return;
  113. }
  114. PCVOR temp = *head;
  115. PCVOR temp_next = temp->next;
  116. if (temp->data == find) {
  117. izbaciSaPocetka(head);
  118. return;
  119. }
  120. while (temp_next->data != find) {
  121. temp = temp_next;
  122. temp_next = temp_next->next;
  123. }
  124. if (temp_next->next == NULL) {
  125. izbaciSaKraja(head);
  126. return;
  127. }
  128. PCVOR delete = temp_next;
  129. temp_next = temp_next->next;
  130. temp->next = temp_next;
  131. free(delete);
  132. }
  133. void prebacivanjeNeparnih(PCVOR* head, PCVOR* neparni)
  134. {
  135. PCVOR org = *head;
  136. while (org != NULL) {
  137. if (org->data % 2 != 0) {
  138. ubaciNaKraj(neparni, org->data);
  139. }
  140. org = org->next;
  141. }
  142. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement