Question: Chapter 7 - Programming Project: implement a singly linked list with following functions: - add _ head ( e ) - add _ tail (
Chapter Programming Project: implement a singly linked list with following functions:
addheade
addtaile
findrdtolast returns element located at thirdtolast in the list
reverse reverse the linked list, note, this is not just printing elements in reverse order, this is actually reversing the list
Use the base code in python below:
class Node:
This class represents a node in a singly linked list.
Each node has a value and a reference to the next node in the list.
def initself dataNone:
self.data data
self.next None
class SinglyLinkedList:
# Assignment: Programming Project, Chapter
def initself:
self.head None
self.tail None
def addheadself e:
This function adds an element at the head of the list.
Parameters:
e Any: The element to add.
Returns:
None
# WRITE YOUR CODE HERE
def addtailself e:
This function adds an element at the tail of the list.
Parameters:
e Any: The element to add.
Returns:
None
# WRITE YOUR CODE HERE
def findrdtolastself:
This function finds the thirdtolast element in the list.
Parameters:
None
Returns:
Any: The thirdtolast element in the list, or None if the list has fewer than three elements.
# WRITE YOUR CODE HERE
return None
def reverseself:
This function reverses the list.
Parameters:
None
Returns:
None
# WRITE YOUR CODE HERE
if namemain:
linkedlist SinglyLinkedList
linkedlist.addhead
linkedlist.addtail
linkedlist.addtail
linkedlist.addtail
printlinkedlist.findrdtolast #
linkedlist.reverse
printlinkedlist.findrdtolast #
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
