You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
1.0 KiB

4 years ago
4 years ago
4 years ago
4 years ago
  1. /*
  2. * linkedlist.c
  3. *
  4. * Created by Yigit Colakoglu on 07/06/2021.
  5. * Copyright yigit@yigitcolakoglu.com. 2021. All rights reserved.
  6. */
  7. #include "linkedlist.h"
  8. #include <stdlib.h>
  9. #include <string.h>
  10. #include <stdio.h>
  11. LinkedList *linkedlistalloc(void){
  12. return (LinkedList *) malloc(sizeof(LinkedList));
  13. }
  14. int linkedlistfind(LinkedList *p, char *str) {
  15. int count = 0;
  16. while(p != NULL){
  17. if(!strcmp(p->data, str))
  18. return count;
  19. count++;
  20. p = p->next;
  21. }
  22. return -1;
  23. }
  24. LinkedList *linkedlistadd(LinkedList *p, char *data){
  25. if(p == NULL){
  26. p = linkedlistalloc();
  27. p->next = NULL;
  28. p->data = data;
  29. }else
  30. p->next = linkedlistadd(p->next, data);
  31. return p;
  32. }
  33. void linkedlistprint(LinkedList *p, FILE *out, char* payload){
  34. if(p != NULL){
  35. (p->data == NULL) ? fprintf(out, "NULL=NULL") : fprintf(out, "%s=%s", p->data, payload);
  36. (p->next == NULL) ? : fprintf(out, "%c",'&');
  37. linkedlistprint(p->next, out, payload);
  38. }
  39. }