Advertisement
KAR98S

Operations.c

Apr 23rd, 2021
721
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.14 KB | None | 0 0
  1. #include "Operations.h"
  2.  
  3.  
  4. void printLinkedList(PNODE head) {
  5.     do {
  6.         printf("%d -> ", head->data);
  7.     } while ((head = getNextNode(head)) != NULL);
  8.     printf("NULL");
  9. }
  10.  
  11. //TODO:
  12. _Bool findElement(PNODE head, int data) {
  13.     while (head != NULL)break;
  14.     return false;
  15. }
  16.  
  17. //add traverse comparison with this vs. array using clock()
  18. PNODE traverse_a(PNODE head, int distance) {
  19.     if (head != NULL) {
  20.         if (distance) {
  21.             while ((--distance) && (head->next != NULL))head = head->next;
  22.         }
  23.         else {
  24.             while (head->next != NULL)head = head->next;
  25.         }
  26.     }
  27.     return head;
  28. }
  29.  
  30. PNODE insertNormal(PNODE head, int data, int *size) {
  31.     PNODE cur = traverse_end(head);
  32.     //printf("%x", cur);
  33.     //_getch();
  34.     if (cur)
  35.         cur = (cur->next = getNewNode());
  36.     else
  37.         cur = calloc(1, NODESIZE);
  38.     cur->data = data;
  39.     (*size)++;
  40.     return ((head)?head:cur);
  41. }
  42.  
  43. PNODE deleteNormal(PNODE head, int* size) {
  44.     if (head != NULL) {
  45.         PNODE cur = traverse(head, (*size) - 1), tmp = NULL;
  46.         if (*size != 1) {
  47.             tmp = cur;
  48.             cur = getNextNode(cur);
  49.             tmp->next = NULL;
  50.         }
  51.         free(cur);
  52.         (*size)--;
  53.         return (((*size)) ? head : NULL);
  54.     }
  55.     return NULL;
  56. }
  57.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement