Data Structures: Linked Lists

Linked lists are data structures that consists of a group of nodes in a sequence. Each node contains data and a reference/link to the next node in the sequence. (Picture 1) Pros of linked lists: - dynamic, allocating the required memory at run time - insertion/deletion node operation easily implemented (Picture 2) - stacks & queues easily done with linked lists - reduced access time Cons: - wastes memory because pointers require extra storage space - nodes must be read in order (beginning to end) - nodes stored incontiguously -> increases time required to access specific elements Implementation: Usually implemented using a struct or class that contains the variables holding your data and a pointer. Example in C++: struct node { int x; // holds the data node *next; // pointer that helps us }; int main() { node *root; // unchanging first node root = new node; // Now root points to a node struct root->next = 0; // The node root points to has its next pointer // set equal to a null pointer root->x = 5; // By using the -> operator, you can modify the node // a pointer (root in this case) points to. }

we've got science!
4.7 Star App Store Review!***uke
The Communities are great you rarely see anyone get in to an argument :)
Love Love LOVE