Chapter - 35 Lists and linked lists Flashcards
What is a list?
» Ordered data structure
» Dynamic
» Accessing the data involves using an index
What is the operation to test an empty list?
» isEmpty()
What is the operation to add a new item to list to the end of the list?
» Append(item)
What operation is used to remove the first occurrence of an item from the list?
» remove(item)
What operation is used to search for an item in a list?
» search(item)
What operation can you use to return the number of items in a list?
» length()
What operation can return the position of an item?
» index(item)
What operation can insert a new item at a position number?
» insert(pos,item)
What operation can remove and return the last item in the list?
» pop()
What operation can remove and return the item at a position number?
» pop(pos)
What is the difference between an array and a list?
» List is dynamic
» Array is static
How do you insert a new name in the list?
» Test whether the list is already full, print message if it is and quit
» Determine where new item needs to be inserted
» Starting at the end of the list, move other items along one piece
» Insert new item in correct place
How do you delete a name from the list?
» First delete the name
» Names coming after deleted item need to me moved up to fill the empty space - by copying them to the previous spot in the array
» Finally the last element which is now duplicated is replaced with a blank
What is a linked list?
» Dynamic data structure used to hold an sequence
» It provides a foundation upon which other structures can be built
What are some features of a linked list?
» Items which form the sequence are not necessarily held in contiguous data locations, or in the order in which they occur in the sequence
What is each item in the linked list called?
» A Node
» Contains a data field and a next address field called a link or pointer field
What does the data field contain?
» Actual data associated with the list item
What does the pointer field contain?
» The address of the next item in the sequence
What is the use of the null pointer?
» The link field in the last item indicates that are no further items by the use of a null pointer
What is the start pointer?
» Identifies the first node in the list
How do we initialize a linked list?
» Keep two linked lists
» One for the actual data
» One for the free space
What does the start pointer aim to in a new initalised linked list?
» First item in the list, initialised to null
What does null indicate?
» A list is empty
Which pointer does the last item of an empty list have?
» Pointer of null