Python homework:how to write and test a _swap method for the linked Deque. def _
ID: 3808612 • Letter: P
Question
Python homework:how to write and test a _swap method for the linked Deque.
def _swap(self, l, r):
""" -------------------------------------------------------
Swaps two pointers. Use: self._swap(self, l, r):
-------------------------------------------------------
Preconditions:
l - a pointer to a deque node (_DequeNode)
r - a pointer to a deque node (_DequeNode)
Postconditions: l has taken the place of r, r has taken the place of l _front and _rear are updated as appropriate
-------------------------------------------------------
"""
assert l is not None and r is not None, "nodes to swap cannot be None"
please give a thinking of this, I don;t know which method to use.
Explanation / Answer
The phyton deque is consist of doubly linked list data. The main aim to use phyton deque is useful for pushing the information and popping the information for better indexing purposes. It is mainly consist in Collections.deque class. It supports the thread concepts and all.
I have written the swap method which swaps the list and i included the comments in the program:-
Code:
//main method
def _swap(self, l, r):
{
// declaring variables
l = 200
r = 300
//display the output
print "Before Exchange : l = %d r = %d ",l,r
exchange(&l,&r);
printf " After Exchange : l = %d r = %d ",l,r
}
exchange(x,y)
Use: self._swap(self, *x, *y):
{
// create a temp variable
t;
t = *x;
*x = *y;
*y = t;
return(*x,*y);
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.