Here is the completed code for this problem. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. Make sure that you maintain proper indentations while pasting the below code into your program, I’m also attaching the code in both text and image formats, so in case if the indentation is messed up, you can refer the image and maintain proper spacing in each and every line. Thanks
If you are satisfied with the solution, please rate the answer. If not, let me know before you rate the answer, I’ll correct anything you want.
#code
def reverse_pure(lst):
#defining an empty list
reversed=[]
#finding last index of parameter list
index=len(lst)-1
#iterating from rear to front
while index>=0:
#adding current
element to new list
reversed.append(lst[index])
index-=1 #previous
index
return reversed
#returning new list containing elements in reverse
order
def reverse_mut(lst):
#finding the length of lst list
size=len(lst)
#looping from i=0 to i=size/2
for i in
range(size//2):
#swapping elements
at index i and index size-i-i
#that is swapping ith
element from front and ith element from rear
temp=lst[i]
lst[i]=lst[size-1-i]
lst[size - 1 -
i]=temp
#end of method, now the lst will be in
reverse order.
#testing
myList=[5,12,34,0,1]
newList=reverse_pure(myList)
print(newList) # [1, 0, 34, 12, 5]
print(myList) # [5, 12, 34, 0, 1]
reverse_mut(myList)
print(myList) # [1, 0, 34, 12, 5]
#code screenshot
![1 def reverse_pure(1st): #defining an empty list reversed-[] #finding last index of parameter list index-len(1st)-1 #iterating from rear to front while index>-e: 4 9 1e #adding current element to new list reversed.append (1st[index]) index-=1 #previous index return reversed #returning new list containing elements in reverse order 12 13- 14 15 16 17 18 19 def reverse-mut(1st): #finding the length of 1st list size-len(lst) #looping from i-e to i size/2 for i in range(size//2): #swapping elements at index i and index size-i-i #that is swapping ith element from front and ith element from rear temp-1st[i] 1st[i]-lstisize-1-i] 1st[size - 1 - i]-temp #end of method, now the 1st will be in reverse order. 24 25 26 27 28 29 30 31 #testing myList-[5,12,34,0,1] newList-reverse_pure(myList) print(newList) # [1, 0, 34, 12, 5] print(myList) # [5, 12, 34, 0, 1] reverse_mut(myList) print(myList) # [1, , 34, 12, 5]](http://img.homeworklib.com/questions/7f7f6940-3e81-11eb-afd9-5b94c2bb95dc.png?x-oss-process=image/resize,w_560)
#output
[1, 0, 34, 12, 5]
[5, 12, 34, 0, 1]
[1, 0, 34, 12, 5]
Problem 8 In class, we discussed the difference between a pure (or effect-free) function (i.e. one...
C++ Linked List Implementation Motivation As we discussed in class, the data structures that you use to implement your program can have a profound impact on it's overall performance. A poorly written program will often need much more RAM and CPU time then a well-written implementation. One of the most basic data structure questions revolves around the difference between an array and a linked list. After you finish this assignment you should have a firm understanding of their operation. Problem...
Write a Python program that tests the function main and the
functions discussed in parts a through g.
Create the following lists:
inStock - 2D list (row size:10, column
size:4)
alpha - 1D list with 20 elements.
beta - 1D list with 20 elements.
gamma = [11, 13, 15, 17]
delta = [3, 5, 2, 6, 10, 9, 7, 11, 1, 8]
a. Write the definition of the function setZero
that initializes any one-dimensional list to 0
(alpha and beta)....
Please write a code in Java where it says your // your code here to run the code smoothly. Import statements are not allowed. _ A Java method is a collection of statements that are grouped together to perform an operation. Some languages also call this operation a Function. When you call the System.out.println() method, for example, the system actually executes several statements in order to display a message on the console. Please write the code according to functions assigned...
Please write a code in Java where it says your // your code here to run the code smoothly. Import statements are not allowed for this assignment, so don't use them. _ A Java method is a collection of statements that are grouped together to perform an operation. Some languages also call this operation a Function. When you call the System.out.println() method, for example, the system actually executes several statements in order to display a message on the console. Please...
-------------------------------------------------------------------- 1. How does Java support the concept of encapsulation? -------------------------------------------------------------------- 2. Describe the difference between an object and a class. -------------------------------------------------------------------- 3. What is the difference between the contents of a Java variable of a primitive type and a Java variable of a class type? -------------------------------------------------------------------- 4. (a) How is a 'static' class method different from a regular (non-static) class method? (b) How is a 'static' variable in a class different from a regular (instance) variable in a class?...
can someone please double check my code here are the requirements please help me fulfill the requirements Using the material in the textbook (NumberList) as a sample, design your own dynamic linked list class (using pointers) to hold a series of capital letters. The class should have the following member functions: append, insert (at a specific position, return -1 if that position doesn't exist), delete (at a specific position, return -1 if that position doesn't exist), print, reverse (which rearranges...
Problem Set 2: Inheritance and Method Overriding The goal of this problem set is to apply inheritance and method overriding in order to create a hierarchy of array sorters. There exist many algorithms to sort arrays. In this problem set, we are especially interested in “in-place” sorting algorithms like Selection Sort and Insertion Sort. In-place sorting refers to an approach in which we perform the sorting steps on the underlying array rather than using extra storage. When using object-oriented design,...
Complete function long_list_printer.print_list(). When it's
finished, it should be able to print this list,
a = [
[93, 80, 99, 72, 86, 84, 85, 41, 69, 31],
[15, 37, 58, 59, 98, 40, 63, 84, 87, 15],
[48, 50, 43, 68, 69, 43, 46, 83, 11, 50],
[52, 49, 87, 77, 39, 21, 84, 13, 27, 82],
[64, 49, 12, 42, 24, 54, 43, 69, 62, 44],
[54, 90, 67, 43, 72, 17, 22, 83, 28, 68],
[18, 12, 10,...
Hello I need help with this program. Should programmed in C!
Program 2: Sorting with Pointers Sometimes we're given an array of data that we need to be able to view in sorted order while leaving the original order unchanged. In such cases we could sort the data set, but then we would lose the information contained in the original order. We need a better solution. One solution might be to create a duplicate of the data set, perhaps make...