def llIndex_Value (head, n): pass def llDelete_Last_item(head): pass
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
Related questions
Question
I need help with the last two functions in python
Expert Solution
Step 1c
I have implemented the question in python as per the specification. I have also added a sample main function to run the provided test case and print the correct output. The code is as follows:
class ListNode:
def__init__(self,data,next=None)->None:
self.data=data
self.next=next
def__str__(self)->str:
temp=self
result=[]
whiletemp!=None:
result.append(str(temp.data))
temp=temp.next
result.append(str(None))
return"->".join(result)
defllSize(self):
temp=self
count=0
whiletemp!=None:
count+=1
temp=temp.next
returncount
defllIndex_Value(self,n):
temp=self
whiletemp!=Noneandn>=0:
ifn==0:
returntemp.data
else:
n-=1
temp=temp.next
returnNone
defllDelete_Last_Item(self):
temp=self
prev=self
whiletemp.next!=None:
prev=temp
temp=temp.next
prev.next=None
returntemp.data
if __name__ == "__main__":
node7=ListNode(7)
node6=ListNode(6,node7)
node4=ListNode(4,node6)
node1=ListNode(1,node4)
print(node1)
print(node1.llSize())
print(node1.llIndex_Value(3))
print(node1.llDelete_Last_Item())
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY