Question: class LinkedList: class Node: def __init__(self, val, prior=None, next=None): self.val = val self.prior = prior self.next = next def __init__(self): self.head = LinkedList.Node(None) self.head.prior =

class LinkedList:

class Node:

def __init__(self, val, prior=None, next=None):

self.val = val

self.prior = prior

self.next = next

def __init__(self):

self.head = LinkedList.Node(None)

self.head.prior = self.head.next = self.head

self.length = 0

def prepend(self, value):

n = LinkedList.Node(value, prior = self.head, next = self.head.next)

self.head.next = n

self.head.next.prior = n

self.length += 1

def append(self, value):

n = LinkedList.Node(value, prior= self.head.prior, next = self.head)

n.prior.next = n

n.next.prior = n

self.length += 1

class LinkedList: class Node: def __init__(self, val, prior=None, next=None): self.val = val

Please used Python 3

2 For this problem, you are to implement the guided_iter method of a circular, doubly- linked list with a sentinel head. When called with an array of integers (called "steps"), guided_iter will return an iterator over elements in the list reached by traversing (backwards or forwards) over the number of elements specified by each integer, starting at index 0. E.g., given the list 1-['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'], 1.guided_iter([3, 1, 2]) will return an iterator over ['d', 'e', 'g'] l.guided_iter([O, -2, -4]) will return an iterator over ['a', 'i', 'e'] o 1.guided_iter([4, 1, 0, 8, -5]) will return an iterator over Note that negative step values indicate backwards traversal and positive step values indicate forward traversal large values may cause multiple "loops" to be taken around the elements in a list (ignoring, of course, the sentinel head) Restrictions/Assumptions: Your implementation should not make use of any other list methods (e.g.,?get item-) You may assume that the list contains at least one element. You may assume the input steps are all integers

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!