Advertisement
notABoyNamedSue

Untitled

Sep 12th, 2016
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <math.h>
  4. #include <string.h>
  5. #include "linkedlist.h"
  6.  
  7. struct linkedList
  8. {
  9. char *data;
  10. int key;
  11. int left;
  12. int right;
  13. int size;
  14. };
  15.  
  16. LinkedList createLinkedList(int size)
  17. {
  18. LinkedList newLL = malloc(sizeof *newLL);
  19. newLL->data = malloc(sizeof(int) * (size+1));
  20. newLL->size = size;
  21. newLL->left = 0;
  22. newLL->right = 0;
  23. return newLL;
  24. }
  25.  
  26. bool isFull(LinkedList LL)
  27. {
  28. return abs(abs(LL->left)- abs(LL->right)) == LL->size;
  29. }
  30.  
  31. void insertFront(LinkedList LL, const char * newInfo)
  32. {
  33. if(isFull(LL))
  34. {
  35. printf("FULL");
  36. exit(1);
  37. }
  38.  
  39. LL->data[((--(LL->left) % LL->size) + LL->size) % LL->size] = newInfo;
  40. }
  41.  
  42. bool isEmpty(LinkedList LL)
  43. {
  44. return LL->left == LL->right;
  45. }
  46.  
  47. const char * removeEnd(LinkedList LL)
  48. {
  49. if(isEmpty(LL))
  50. {
  51. const char * statement;
  52. statement = "EMPTY";
  53. return statement;
  54. }
  55. return LL->data[((--(LL->right) % LL->size) + LL->size) % LL->size];
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement