Advertisement
Guest User

Untitled

a guest
Nov 21st, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. static struct node* createListNode(const Data data)
  2. {
  3. struct node* newNode;
  4. newNode = (struct node*)malloc(sizeof(int));
  5. if (newNode == NULL)
  6. {
  7. printf("Allocation of memory for the node failed");
  8. return NULL;
  9. }
  10. newNode->data = data;
  11.  
  12. //Glom inte att testa sa att allokeringen lyckades innan du initierar noden
  13. return newNode; //Ersatt med ratt returvarde
  14. }
  15.  
  16. List createEmptyList(void)
  17. {
  18. return NULL;
  19. }
  20.  
  21. int isEmpty(const List list)
  22. {
  23. if (list == NULL) {
  24. return 1;
  25. }
  26. return 0; //ersatt med ratt returvarde
  27. }
  28.  
  29. /*Lagg till nod forst i listan*/
  30. /*Postcondition: Det nya datat ligger forst i listan (testa med assert)*/
  31. void addFirst(List *list, const Data data)
  32. {
  33. struct node* newNode = createListNode(data);
  34. assert(newNode != NULL);
  35. if (list != NULL) {
  36. newNode->next = list;
  37. }
  38. list = newNode;
  39.  
  40. //Anropa createListNode for att skapa den nya noden
  41. //Glom inte att testa att den nya noden faktiskt kunde skapas/tilldelas minne innan du fortsatter
  42. //Tank pa att listan kan vara tom nar en ny nod laggs till
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement