Inserting and deleting in a linked list

Inserting into a list  chained

Inserting into a linked list has three steps:
  • Create link.
  • Set the value to be inserted to the val.
  • Insert the new block into the list.

How do I create a link?

  • Allocate a space with the predefined procedure  allouer.
  • Pass the p pointer to the allocate procedure to render the address.
    • allocation(p): allocate link or block in a chained list

Insert the link at the top


Inserting the link at the top

Inserting the link away from the head

Inserting the link away from the head

Insert(L: chainlisted, e: element, pp: ptr)
start
    allouer(p)
    *p.val := e
    *p.link:= *pp.link
    *pp.link:= p
fin

Delete from a linked list

just eliminate the link to be deleted by modifying the address fields of the link that points to it (predecessor).

Removed the lead link





Removed link other than header





Procedure delete(L: chainlisted, pp: ptr)
start
    p := *pp.lien
    *pp.link:= *p.link
    renderer(p)
fin