![]() I suggest you rename link to next which is a more conventional name for the next linked list node. What other functions apart from the four currently installed, would you recommend to implement as an exercise? ![]() Two more things apart from the criticism:Īm I using the free() function properly? Is the structure actually being removed from the dynamic memory? adjust the new tail and point it to NULL get reference of the head to iterate through linked list Function deletes node at the end of the linked list PointerToLinkedList = pointerToLinkedList->link adjust pointerToLinkedList to the new head (previously the second node) get reference of the head that will be deleted Function deletes node at the beginning of the linked list Struct node *secondLastNode = pointerToLinkedList link second last node to the newly created last node of the linked list point new node to NULL, because its last node in list ![]() Function inserts a new node at the end of the linked list adjust pointerToLinkedList accordingly with the new head The best solution is to make a thin wrapper to call the linked list you already wrote. point new node to the previous head (now second node in linked list) Struct node *newNode = (struct node*) malloc(sizeof(struct node)) Function inserts a new node at the beginning of the linked list Structure represents a node of a Linked List All I am looking for is some criticism, such as how to make the functions more efficient or defining *pointerToLinkedList in a better spot. I have been reading about pointers in C and I thought implementing a linked list would be a good exercise to test my knowledge.īelow is my code and it is 100% functional.
0 Comments
Leave a Reply. |