In this problem, you will write some code for operations on a singly linked list where...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
In this problem, you will write some code for operations on a singly linked list where values in each Node are integers only. Assume you already have the following code. Assume the method bodies, even though not shown, are correct and implement the operations as we defined them in lecture. class Node: definit (self, value): value self.value self.next None def_str_(self): ***String representation of Node object*** repr__str_ class Linkedlist: definit__(self): self.head-None self. tail-None def_str_(self): repr_=_str_ def isEmpty(self): deflen_(self): *** String representation of LinkedList object""" "*" Returns True when list is empty, False otherwise""" ***Returns the number of nodes in the list *** Write the implementation for the special method_contains__(self, value) in the LinkedList class that returns True when the list contains a Node with that value, False otherwise, but when a Node is found by this method, it moves the Node to the front of the list without changing the relative order of the other nodes. You can assume the values in the list are unique. Be sure to handle the cases of moving the last node! To receive any credit for this question, you are NOT allowed to create new nodes, swap data between nodes or copy elements of the linked list into a Python list (or any other data structure) >>> 1st Head: Node(-5) Tail: Node (9) List: -5 Example: >>> 1st Head: Node(7) Tail: Node (9) List: 7-1-3-4-5-8->9 >>> -5 in 1st True >>> 1st Head: Node(-5) Tail: Node (9) List: -57-13 4 8 9 >>> 33 in 1st False 7 1 3 4 8 9 In this problem, you will write some code for operations on a singly linked list where values in each Node are integers only. Assume you already have the following code. Assume the method bodies, even though not shown, are correct and implement the operations as we defined them in lecture. class Node: definit (self, value): value self.value self.next None def_str_(self): ***String representation of Node object*** repr__str_ class Linkedlist: definit__(self): self.head-None self. tail-None def_str_(self): repr_=_str_ def isEmpty(self): deflen_(self): *** String representation of LinkedList object""" "*" Returns True when list is empty, False otherwise""" ***Returns the number of nodes in the list *** Write the implementation for the special method_contains__(self, value) in the LinkedList class that returns True when the list contains a Node with that value, False otherwise, but when a Node is found by this method, it moves the Node to the front of the list without changing the relative order of the other nodes. You can assume the values in the list are unique. Be sure to handle the cases of moving the last node! To receive any credit for this question, you are NOT allowed to create new nodes, swap data between nodes or copy elements of the linked list into a Python list (or any other data structure) >>> 1st Head: Node(-5) Tail: Node (9) List: -5 Example: >>> 1st Head: Node(7) Tail: Node (9) List: 7-1-3-4-5-8->9 >>> -5 in 1st True >>> 1st Head: Node(-5) Tail: Node (9) List: -57-13 4 8 9 >>> 33 in 1st False 7 1 3 4 8 9
Expert Answer:
Answer rating: 100% (QA)
output This code defines the contains method which s... View the full answer
Related Book For
Introduction to Algorithms
ISBN: 978-0262033848
3rd edition
Authors: Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest
Posted Date:
Students also viewed these programming questions
-
Prior to the first month of operations ending January 31, Lemke Inc. estimated the following operating results: Line Item Description Amount Sales (25,000 $80) $2,000,000 Manufacturing costs (25,000...
-
The second programming project involves writing a program that examines a file of polynomials and determines whether the polynomials in that file are in strictly ascending order using two different...
-
Consider the model Y;jk = + a; + Bi + Yij + Eijk with i = 1,...,I, j= 1,...,J, k = 1,...,K. Show if effects are ~ x. considered random then CY E(CMY)
-
How does Apple Inc apply Marketing and Advertising To market their product? Direct advertising Indirect Advertising Social Media (Paid Media, Owned Media, Earned Media)
-
Inventoriable Costs in your audit of Garza Company, you find that a physical inventory on December 31, 2010, showed merchandise with a cost of $441,000 was on hand at that date. You also discover the...
-
Explain how freight charges, purchase returns, and purchase discounts affect the cost of inventory.
-
An electromagnet in a physics laboratory is damaging electronic apparatus in its vicinity. You suspect that the damage is due to unusually large induced currents created each time the electromagnet...
-
Blake Weaver, Cook Enterprises' controller, is preparing the financial statements for 2013. He has completed the comparative balance sheets and income statement, which follow, and has gathered this...
-
1 What is HRM 2 What is Training and Developmnt 3 What is Recruitment 4 What is Selection 5 What is HRP 6 What is Job Analysis 7 What is a Career Planning and Development 8 What is Job-Description 9...
-
Although the company has already established medical and retirement plan benefits, Toni Prevosti wants to consider other benefits to attract employees. As the company's accountant, you have been...
-
explain what your focus is on more efficient runway usage.
-
Company K purchased $1 million face value of bonds issued by company J on 1 July 2015 at purchase cost of $1.05 million. The bond had coupon of 6% payable semi-annually and matures on 30 June 2017....
-
If Gemini has a floating rate loan and enters into a pay-fixed-and-receive-floating interest swap transaction with the same principal amount, which of the following statements is the most appropriate...
-
Explain the following terms: (a) Grant date (b) Measurement date (c) Vesting date (d) Vesting conditions (e) Forfeiture rate
-
In what situations can a hedged item be either a fair value hedge or a cash flow hedge? Explain why each type of hedge is applicable to the situation.
-
A firm that intends to hedge against commodity price risk has to decide whether to use a forward contract or an options contract to hedge the risk. What factors should the firm consider before...
-
Data was collected for the reaction: 3 AB2(g) 3 AB(g) + B3(g), and the following plots were created. What is the order of the reaction with respect to AB2? ww.otx) l'avi 1.0 0.8- 0.6- 0.4 0.24 60 120...
-
Willingness to pay as a measure of a person's value for a particular good measures the maximum a person would be willing to pay requires that payment actually be made depends on the satisfaction that...
-
A self-organizing list is a linked list of n elements, in which each element has a unique key. When we search for an element in the list, we are given a key, and we want to find an element with that...
-
Show that a set of n line segments may contain (n 2 ) intersections.
-
Professor Diogenes has n supposedly identical integrated-circuit chips that in principle are capable of testing each other. The professor?s test jig accommodates two chips at a time. When the jig is...
-
Lennon Industries had the following transactions. 1. Borrowed 5,000 from the bank by signing a note. 2. Paid 3,900 cash for a computer. 3. Purchased 650 of supplies on account. Instructions a....
-
Ong Enterprises had the following selected transactions. 1. Shareholders invested NT\($40,000\) cash in the business in exchange for ordinary shares. 2. Paid office rent of NT\($8,400. 3. Performed...
-
The T-accounts below summarize the ledger of Negrete Landscaping at the end of the first month of operations (amounts in ). Instructions a. Prepare the complete general journal (including...
Study smarter with the SolutionInn App