Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Fundamentals Of Database Systems

Authors: Ramez Elmasri, Shamkant B. Navathe

7th Edition Global Edition

1292097612, 978-1292097619

More Books

Students also viewed these Databases questions