Question: Create a python function with the spec given above 6 insert_at(old head, new node, pos) This function inserts a node into an existing list. You

Create a python function with the spec given above 6 insert_at(old head,Create a python function with the spec given above

6 insert_at(old head, new node, pos) This function inserts a node into an existing list. You may assume that the new node will definitely not be None, but the old list certainly might be empty. Instead of inserting this new node at the head, the tail, or based on a sorted ordering, you will instead insert at a given position. If pos==0, then you must insert at the head; if pos==1, then you must insert after the first node, and so on. If the old list is empty, then it is perfectly valid to insert a new node, although the only valid position is 0 (insert at the head). You must include assertions which validate that the position is sensible. You must not allow negative indices, or indices which are past the end of the list. (For instance, if the old list has 3 elements, the the only valid values for pos are 0 (insert at the head), 1, 2, or 3 (insert at the tail). Return the updated list. 6 insert_at(old head, new node, pos) This function inserts a node into an existing list. You may assume that the new node will definitely not be None, but the old list certainly might be empty. Instead of inserting this new node at the head, the tail, or based on a sorted ordering, you will instead insert at a given position. If pos==0, then you must insert at the head; if pos==1, then you must insert after the first node, and so on. If the old list is empty, then it is perfectly valid to insert a new node, although the only valid position is 0 (insert at the head). You must include assertions which validate that the position is sensible. You must not allow negative indices, or indices which are past the end of the list. (For instance, if the old list has 3 elements, the the only valid values for pos are 0 (insert at the head), 1, 2, or 3 (insert at the tail). Return the updated list

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!