Week 9 - Data Structures Self-Referential Structures, Dynamic Memory Allocation, and Linked Lists in C
Week 9 - Data Structures Self-Referential Structures, Dynamic Memory Allocation, and Linked Lists in C
COMPUTING II
• Can link self-referential structure objects to form lists, queues, stacks and
trees
malloc Function
• Request memory by passing to malloc the number of bytes to
allocate
• If successful, it returns a void * pointer to the allocated memory
• Commonly used with sizeof
– newPtr = malloc(sizeof(struct node));
free Function
• Call malloc to create a new node and assign newPtr the allocated
memory’s address