Question: Assignment description: Recall that in a cursor-base list a cursor (indicating the current item ) can be moved around the list with the cursor being

Assignment description:

Recall that in a cursor-base list a cursor (indicating the current item) can be moved around the list with the cursor being used to identify the region of the list to be manipulated. We will insert and removing items relative to the current item. A current item must always be defined as long as the list is not empty.

Assignment description: Recall that in a cursor-base list a cursor (indicating the

The cursor_based_list.py file contains a skeleton CursorBasedList class. You MUST uses a doubly-linked list implementation with a header node and a trailer node. All real list items will be inserted between the header and trailer nodes to reduce the number of special cases (e.g., inserting first item in an empty list, deleting the last item from the list, etc.). An empty list looks like:

current item) can be moved around the list with the cursor being

Please complete the following Python code for this assignment.

from node2way import Node2Way

class CursorBasedList(object): """ Linked implementation of a positional list.""" def __init__(self): """ Creates an empty cursor-based list.""" self._header = Node2Way(None) self._trailer = Node2Way(None) self._trailer.setPrevious(self._header) self._header.setNext(self._trailer) self._current = None self._size = 0

def hasNext(self): """ Returns True if the current item has a next item. Precondition: the list is not empty.""" if self.isEmpty(): raise AttributeError("Empty list has no next item") return self._current.getNext() != self._trailer

def hasPrevious(self): """ Returns True if the current item has a previous item. Precondition: the list is not empty.""" pass def first(self): """Moves the cursor to the first item if there is one. Precondition: the list is not empty.""" pass def last(self): """Moves the cursor to the last item if there is one. Precondition: the list is not empty.""" pass

def next(self): """Precondition: hasNext returns True. Postcondition: The current item is has moved to the right one item""" pass

def previous(self): """Precondition: hasPrevious returns True. Postcondition: The current item is has moved to the left one iten""" pass

def insertAfter(self, item): """Inserts item after the current item, or as the only item if the list is empty. The new item is the current item.""" pass

def insertBefore(self, item): """Inserts item before the current item, or as the only item if the list is empty. The new item is the current item.""" pass

def getCurrent(self): """ Returns the current item without removing it or changing the current position. Precondition: the list is not empty""" pass

def remove(self): """Removes and returns the current item. Making the next item the current item if one exists; otherwise the tail item in the list is the current item. Precondition: the list is not empty.""" pass

def replace(self, newItemValue): """Replaces the current item by the newItemValue. Precondition: the list is not empty.""" pass

def isEmpty(self): pass

def __len__(self): """ Returns the number of items in the list.""" # replace below return 0

def __str__(self): """Includes items from first through last.""" # replace below return ""

Description of operation Precondition: the list is not empty. Returns the current item without removing it or changing the current position Precondition: the list is not empty. Returns True if the current item has a next item; otherwise return False Precondition: hasNext returns True, Postcondition: The current item has moved right one item Precondition: the list is not empty. Returns True if the current item has a Cursor-based operations .getCurrent ( ) L .hasNext () .next ( ) L.hasPrevious () L.previous () revious item; otherwise return False Precondition: hasPrevious returns True. Postcondition: The current item has moved left one item Precondition: the list is not empty. Makes the first item the current item Precondition: the list is not empty. Makes the last item the current item L.first () L.last () L.insertAfter (item) Inserts item after the current item, or as the only item if the list is empty. The new item is the current item .insertBefore ( item) | Inserts item before the current item, or as the only item if the list is empty. The new item is the current item L.replace (newValue) Precondition: the list is not empty. Replaces the current item by the newValue .remove ( ) Precondition: the list is not empty. Removes and returns the current item Making the next item the current item if one exists; otherwise the tail item in the list is the current item unless the list in now empt Description of operation Precondition: the list is not empty. Returns the current item without removing it or changing the current position Precondition: the list is not empty. Returns True if the current item has a next item; otherwise return False Precondition: hasNext returns True, Postcondition: The current item has moved right one item Precondition: the list is not empty. Returns True if the current item has a Cursor-based operations .getCurrent ( ) L .hasNext () .next ( ) L.hasPrevious () L.previous () revious item; otherwise return False Precondition: hasPrevious returns True. Postcondition: The current item has moved left one item Precondition: the list is not empty. Makes the first item the current item Precondition: the list is not empty. Makes the last item the current item L.first () L.last () L.insertAfter (item) Inserts item after the current item, or as the only item if the list is empty. The new item is the current item .insertBefore ( item) | Inserts item before the current item, or as the only item if the list is empty. The new item is the current item L.replace (newValue) Precondition: the list is not empty. Replaces the current item by the newValue .remove ( ) Precondition: the list is not empty. Removes and returns the current item Making the next item the current item if one exists; otherwise the tail item in the list is the current item unless the list in now empt

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!