Lists - Chapter 2 Flashcards
A blank is a common ADT for holding ordered data, having operations like append a data item, remove a data item, search whether a data item exists, and print the list
list
Inserts x at end of list
Append(list, x)
Inserts x at start of list
Prepend(list, x)
Inserts x after w
InsertAfter(list, w, x)
Removes x
Remove(list, x)
Returns item if found, else returns null
Search(list, x)
Prints list’s items in order
Print(list)
Prints list’s items in reverse order
PrintReverse(list)
Sorts the lists items in ascending order
Sort(list)
Returns true if list has no items
IsEmpty(list)
Returns the number of items in the list
GetLength(list)
common approach for implementing a linked list is using what two data structures
List data structure:
List node data structure:
A blank is a data structure containing the list’s head and tail, and may also include additional information, such as the list’s size.
list data structure
The blank maintains the data for each list element, including the element’s data and pointers to the other list element.
list node data structure
A blank is not required to implement a linked list, but offers a convenient way to store the list’s head and tail.
list data structure
A blank is a data structure for implementing a list ADT, where each node has data and a pointer to the next node.
singly-linked list
A singly-linked list’s first node is called the blank, and the last node the blank.
head
tail
A singly-linked list is a type of blank A list where elements contain pointers to the next and/or previous elements in the list.
positional list:
Blank is a special value indicating a pointer points to nothing.
null
Given a new node, the blank operation for a singly-linked list inserts the new node after the list’s tail node.
Append
Blank: If the list’s head pointer is null (empty), the algorithm points the list’s head and tail pointers to the new node.
Append to empty list:
Blank: If the list’s head pointer is not null (not empty), the algorithm points the tail node’s next pointer and the list’s tail pointer to the new node.
Append to non-empty list
Given a new node, the blank operation for a singly-linked list inserts the new node before the list’s head node.
Prepend
Blank: If the list’s head pointer is null (empty), the algorithm points the list’s head and tail pointers to the new node.
Prepend to empty list
Blank: If the list’s head pointer is not null (not empty), the algorithm points the new node’s next pointer to the head node, and then points the list’s head pointer to the new node.
Prepend to non-empty list
Given a new node, the blank operation for a singly-linked list inserts the new node after a provided existing list node.
InsertAfter
Blank: If the list’s head pointer is null, the algorithm points the list’s head and tail pointers to the new node.
Insert as list’s first node
Blank: If the list’s head pointer is not null (list not empty) and curNode points to the list’s tail node, the algorithm points the tail node’s next pointer and the list’s tail pointer to the new node.
Insert after list’s tail node
Blank: If the list’s head pointer is not null (list not empty) and curNode does not point to the list’s tail node, the algorithm points the new node’s next pointer to curNode’s next node, and then points curNode’s next pointer to the new node.
Insert in middle of list
Given a specified existing node in a singly-linked list, the blank operation removes the node after the specified list node.
RemoveAfter