Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Could any please answer the following question 1.) Give Pseudo code descriptoins

ID: 3609552 • Letter: C

Question

Could any please answer the following question 1.) Give Pseudo code descriptoins of algorithms for performingthe functions insertBefore(p,e), insertFirst(e), and insertLast(e)of the list ADT, assuming the list is implemented using a doublylinked list. Please mention each and every step. Thank you Could any please answer the following question 1.) Give Pseudo code descriptoins of algorithms for performingthe functions insertBefore(p,e), insertFirst(e), and insertLast(e)of the list ADT, assuming the list is implemented using a doublylinked list. Please mention each and every step. Thank you

Explanation / Answer

Algorithm Insert Before (p,e):

Create a new node v

v.setElement(e)

v.setPrev(p.getPrev())

{

link v to its predecessor

}

v.setNext(p)

{

link v to its successor

}

(p.getPrev()).setNext(v)

{

link p’sold predecessor to v

}

p.setPrev(v)

{

link p to its new predecessor, v

}

numElts++

return v {the position for the element e}

Algorithm InsertFirst(e):

Create a new node v

v.setElement(e)

header.getNext().setPrev(v)

v.setNext(header.getNext())

v.setPrev(header)

header.setNext(v)

numElts++

return v

Algorithm InsertLast(e):

Create a new node v

v.setElement(e)

trailer.getPrev().setNext(v)

v.setNext(trailer)

trailer.setPrev(v)

numElts++