Question
Python3
You should use the getters and setters I post in the first pic
157 158 class LinkNode: 159 160 def-initー(self.value,nxt One): assert isinstance(nxt,Lin㎾ode) or nxt is None self.value value
A permutation can be considered as an injective (one-to-one) mapping. For example, the permutation p (1,2,3,4,5) can be consi
def permutation(link, k) ptr temp s while ptr.next is not None: .ptr ptr.next ptr.next-temp >>> del ptr >>> permutation(temp,
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Complete Code:

class LinkNode: def __init_(self, value, nxt=None): assert isinstance (nxt, LinkNode) or nxt is None self.value = value self.

Sample Output:

>>> temp = LinkNode (1, LinkNode (2, LinkNode (3, LinkNode (4, LinkNode (5))))) >>> ptr = temp >>> while ptr.next is not None

CODE TO COPY:

class LinkNode:
    def __init__(self,value,nxt=None):
        assert isinstance(nxt,LinkNode) or nxt is None
        self.value = value
        self.next = nxt
    def get_value(self):
        return self.value
    def set_value(self, value):
        self.value = value
    def get_next(seif):
        return self.next
    def set_next(self,nxt):
        self.next = nxt
    def __repr__(self):
        return repr(self.value)+ ", "+repr(self.next)
  

def permutation(link, k):
    assert isinstance(link,LinkNode) or link is None

    result = []
    count = 0
    curr = link  
    while curr is not None and curr.next is not link:
        count = count + 1
        curr = curr.next      
  
    temp = link  
    for i in range(count+1):
        result.append(temp.value)      
        for j in range(k):
            temp = temp.next      
        result.append(temp.value)
        result.append(None)
        if k == count+1:
            temp = temp.next
      
    return result
  

Add a comment
Know the answer?
Add Answer to:
Python3 You should use the getters and setters I post in the first pic 157 158...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Python question class LinkNode: def __init__(self,value,nxt=None): assert isinstance(nxt, LinkNode) or nxt is None self.value = value...

    Python question class LinkNode: def __init__(self,value,nxt=None): assert isinstance(nxt, LinkNode) or nxt is None self.value = value self.next = nxt Question 2.1. Empty Node In some cases in it convenient to have a notion of an empty linked list. Usually it means that the linked list does not have any elements in it. In order to keep things simple (for now) we will assume that the list is empty, if it has a single node and its value is None. Add...

  • I need a python 3 help. Please help me with this question Part 2. Linked Lists...

    I need a python 3 help. Please help me with this question Part 2. Linked Lists You start working with the class LinkNode that represents a single node of a linked list. It has two instance attributes: value and next. class LinkNode: def __init__(self,value,nxt=None): assert isinstance(nxt, LinkNode) or nxt is None self.value = value self.next = nxt Before you start with the coding questions, answer the following questions about the constructor Valid Constructor or Not? LinkNode(1, 3) LinkNode(1, None) LinkNode(1,...

  • Use of search structures! how can i make this program in python? Learning Objectives: You should...

    Use of search structures! how can i make this program in python? Learning Objectives: You should consider and program an example of using search structures where you will evaluate search trees against hash tables. Given the three text files under containing the following: - A list of students (classes Student in the distributed code) - A list of marks obtained by the students (classes Exam results in the distributed code) - A list of topics (classes Subject in the distributed...

  • I have to use the following theorems to determine whether or not it is possible for...

    I have to use the following theorems to determine whether or not it is possible for the given orders to be simple. Theorem 1: |G|=1 or prime, then it is simple. Theorem 2: If |G| = (2 times an odd integer), the G is not simple. Theorem 3: n is an element of positive integers, n is not prime, p is prime, and p|n. If 1 is the only divisor of n that is congruent to 1 (mod p) then...

  • Attention!!!!!!! I need python method!!!!!!!!! the part which need to edit is below: i nee...

    attention!!!!!!! I need python method!!!!!!!!! the part which need to edit is below: i need python one!!!!!!!!! the part below is interface for the range search tree which don’t need to modify it. Week 3: Working with a BST TODO: Implement a Binary Search Tree (Class Name: RangesizeTree) Choose one language fromJava or Python. Iin both languages,there is an empty main function in the Range Size Tree file. The main function is not tested, however, it is provided for you...

  • please use python and provide run result, thank you! click on pic to make it bigger...

    please use python and provide run result, thank you! click on pic to make it bigger For this assignment you will have to investigate the use of the Python random library's random generator function, random.randrange(stop), randrange produces a random integer in the range of 0 to stop-1. You will need to import random at the top of your program. You can find this in the text or using the online resources given in the lectures A Slot Machine Simulation Understand...

  • I have completed the first 3 questions and I was wondering if my answers I have...

    I have completed the first 3 questions and I was wondering if my answers I have are correct. I am unsure about the T-account for inventory. Also for question 2 letter f do I need to create a journal entry for this one or not? HWK #2 Instrirtinns [1] Swrd tn this PC john sullivan File Home Insert Draw Design Layout References Mailings Review View Help Tell me what you want to do Share Comments Sparty Corporation has been operating...

  • Answer 4 & 5 please! thank you! R values = Resistor value, R1 = 990 Ohms...

    Answer 4 & 5 please! thank you! R values = Resistor value, R1 = 990 Ohms Resistor value, R2 = 2050 Ohms 4. Connect the 2nd resistor in parallel with the 1st resistor and connect that combination to the battery.          Measure the following:               The current passing through the R1, I1 = ___0.0058____ A               The current passing through the R2, I2 = ___0.0031____ A               The current supplied by the battery, I = ___0.0092____ A              Calculate I1 + I2 =...

  • Need help with creating this JavaScript file. I'm not sure where or how to begin. 1. You are working solely with the DOM object. Thus, you should be coding primarily in the js file. You must use...

    Need help with creating this JavaScript file. I'm not sure where or how to begin. 1. You are working solely with the DOM object. Thus, you should be coding primarily in the js file. You must use the addEventListener, in addition you may need to use id and class attributes as needed. The .html and .css files have been provided to you. See the .png files for an example of what is expected. 2. Place the javaScript file in its...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT