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