SYSC 2006 Lecture Notes - Lecture 3: Linked List, C Dynamic Memory Allocation

Introduction:
•
A singly linked list is where every node is connected to other node
A head pointer is a pointer to the list's first node (a.k.a. the head node)
•
typedef struct intnode {
int value;
struct intnode *next;
} intnode_t;
A tail pointer is a pointer to the last node (a.k.a the tail node) to decrease running time of
•
•
Nodes in the singly linked lists are modelled by an intnode_t "type"
•
Value stores an integer and next stores a pointer to the net node in the list
intnode_t *intnode_construct(int value, intnode_t *next)
{
intnode_t *ptr;
ptr = malloc(sizeof(intnode_t));
// assert(ptr != NULL);
ptr
-
>value = value;
ptr
-
>next = next;
return ptr;
}
How To Create a Node:
Introduction to Linked Lists
May 4, 2018
4:46 PM
New Section 1 Page 1