Lists and Linked Lists
BLUF
A list is an abstract data type (ADT) that represents a sequence of elements, where each element has a unique position in the sequence. A list can be implemented using various data structures, such as arrays or linked lists. The list ADT provides a set of operations that can be performed on the list.
The basic operations supported by the list ADT are:
Insert
: Adds an element to the list at a specified position.Delete
: Removes an element from the list at a specified position.Retrieve
: Returns the value of an element at a specified position.Find
: Searches for an element in the list and returns its position.Size
: Returns the number of elements in the list.
In addition to these basic operations, the list ADT may also support other operations, such as:
Concatenate
: Combines two lists into a single list.Split
: Divides a list into two or more sublists.Sort
: Arranges the elements of the list in a specific order.
Lists can be implemented using arrays or linked lists. Arrays have the advantage of constant-time access to any element in the list, but they have a fixed size and may require expensive resizing operations when elements are inserted or deleted. Linked lists, on the other hand, can dynamically grow or shrink as elements are inserted or deleted, but they have a higher overhead due to the need to allocate and deallocate memory for each element.
Some of the commonly used list ADTs in C++ include list
, forward_list
, and vector
. These container classes provide a set of member functions for manipulating lists, such as push_back
, push_front
, insert
, erase
, and size
. The choice of list ADT depends on the specific requirements of the problem at hand.
A linked list is a sequence of elements, known as nodes, where each node contains a data item and a reference (or link) to the next node in the sequence. The list starts with a "head" node, which is the entry point to the list, and ends with a "tail" node, which has a reference to null
, indicating the end of the list. You can traverse the list starting from the head node and following the references to each subsequent node until you reach the tail.
A doubly linked list is similar to a linked list, but each node contains two references: one to the next node and another to the previous node in the sequence. This allows for traversal in both directions: from the head to the tail and from the tail to the head.
Objectives
2024 - Programming 3 / Data Structures - Author: Dr. Kevin Roark