1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
kipiarov [429]
3 years ago
15

Define an iterative function named append_ordered; it is passed two arguments: a linked list (ll) whose values are ordered from

smallest to biggest (they can be ints, strs, anything that can be compared), and another value (v). It returns a reference to the front of a linked list that includes all the values of the original linked list, and v, all in order. We call it like x = append_ordered(x,v). You may create exactly one new LN, for storing the value of v. For example, if we defined x = list_to_ll([1, 3, 8, 12])and wrote the assignment x = append_ordered(x, 10), then str_ll(x) returns the string "1->3->8->10->12->None". Your code should work correctly regardless of whether the other value is added at the front, middle, or rear of the linked list. You may not use any other data structures (e.g., you may not put all the values into a list, sort the list, and then put all the values into a linked list), nor call any other helper functions: write the iterative code.

Computers and Technology
1 answer:
enot [183]3 years ago
3 0

Answer:

A python programming language (code) was used for this exercise.

The code is shown below in the explanation section

Explanation:

Solution

Python code:

class LN:

def __init__(self,value,next=None):

self.value = value

self.next = next

  def list_to_ll(self,l):

if l == []:

return None

front = rear = LN(l[0])

for v in l[1:]:

rear.next = LN(v)

rear = rear.next

return front

  def str_ll(self,ll):

answer = ''

while ll != None:

answer += str(ll.value)+'->'

ll = ll.next

return answer + 'None'

def append_ordered(self,ll,v):

ln1=LN(v); #create a node with the new value by creating an instance of the LN class

if ll is None: #if the linked list is empty

ll=ln1 #return the new created node

elif(ll.value >= ln1.value): #if the value to be add is smallest, append the linked list to it

ln1.next=ll

ll=ln1

else:

current=ll; #crate a temporary pointer to iterate over linked list

#iterate till the next node value is smaller than the new value and list is not over

while (current.next is not None and current.next.value < ln1.value):

current=current.next

ln1.next=current.next #save the current node in the next of the new node

current.next=ln1 #save new node in the next of current node

return ll

ln=LN(0); #create an instance of class LN

ll1=ln.list_to_ll([1,2,4,5]); #create a linked list of the list

answer=ln.str_ll(ll1);    

print(answer); #print the linked list

ll2=ln.append_ordered(ll1,3); #append the value 3 in the linked list

answer=ln.str_ll(ll2)

print(answer); #print the new linked list

Now,

  • If Linked list is empty then make the node as head and return it.
  • If value of the node to be inserted is smaller than value of head node, then insert the node at start and make it head.
  • In a loop, find the appropriate node after which the input node ( 10 ) is to be inserted.To find the appropriate node start from head,keep moving until you reach a node GN (12 ) who's value is greater than the input node. The node just before GN is the appropriate node (8).
  • Insert the node (10) after the appropriate node (8) found in step 3.

Note: Kindly find the output python code attached to the question below.

You might be interested in
If you have related data stored in multiple tables, create a(n) ________ to produce a pivottable on the combined data.
vladimir1956 [14]
If you have related data stored in multiple tables, create a Data model to<span> produce a pivot table on the combined data.
In computer term, data model refers to how each data are connected to one another and how those connections are being processed within the Sysyem</span>
3 0
4 years ago
I need help with Microsoft.
Ipatiy [6.2K]
No clue bro. Im in middle school thats y
7 0
3 years ago
what should the timing of transition slides be per minute? maintain the flow of the presentation to ______ slides per minute.
murzikaleks [220]

Answer:

1-2

Explanation:

It depends on the amount of information that you have on each slide. You want to make sure you're not going too fast but also make sure you arent taking up to much time. Be sure to speak clearly it will make the presentation better by looking clean and time organized. hope this helps :)

8 0
3 years ago
can i get an access code for free online? if yes, what website is it so i can get a free access code?​
PIT_PIT [208]

Answer:

Codecademy. Codecademy is one of the most popular free coding websites for beginners.  

freeCodeCamp.  

Coursera.  

edX.  

Codewars. ..

Code Conquest. .

GA Dash. .

Khan Academy (highly recommed)

:

6 0
2 years ago
what's the best mouse for fast clicking ? I play a lot of fps and a lot of pvp games I need a mouse that I can click fast with a
kondaur [170]
Alenware hp dell logtech, and i know others
7 0
3 years ago
Other questions:
  • How do careers of firefighters and police officer death fire in what ways are they similar​
    6·1 answer
  • An object is suspended in a wind tunnel and the force measured for various levels of wind velocity: v (m/s) 10 20 30 40 50 60 70
    10·1 answer
  • _____ creates a border or space that separates information.
    14·1 answer
  • Create a Trip class. Include as data members destination, distance traveled, total cost of gasoline, and number of gallons consu
    14·1 answer
  • Discuss the following
    14·1 answer
  • Lan is working on a project report that will go through multiple rounds of
    10·1 answer
  • A ___________ variable is used to add up a set of values. fill in the blank
    8·1 answer
  • Please help will give brainliest
    12·1 answer
  • Denise found a volume of documents in the trash bin that contained individuals, names, social security numbers and years of birt
    14·1 answer
  • To stored three characters a computer occupies. Bytes memory space
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!