You are on page 1of 2

Name: Javier Royal

Class:U6

Using a labeled diagram, explain what is a linked list. (7 marks)


A linked list is a series of data items in which each piece of data is connected to the one after it by
means of a pointer. The start of a linked list is called the head and only contains a pointer which is the
address of the first node. A node contains one or more items of data and also a pointer which contains
the address of the next node in the series. The last node in there series will contain an item of data but
point to ’NULL’ as there is nothing after it.

Linked list contains two nodes. using the aid of a diagram in each case, explain
how a new node can be inserted at the:
a) top of the linked list
b) bottom of the linked list
A)

The new node is always added before the head of the given Linked List. And newly added node becomes
the new head of the Linked List. For example, if the given Linked List is 10->15->20->25 and we add an
item 5 at the front, then the Linked List becomes 5->10->15->20->25. Let us call the function that adds at
the front of the list is push(). The push() must receive a pointer to the head pointer because the push
must change the head pointer to point to the new node.
B)

The new node is always added after the last node of the given Linked List. For example if the given
Linked List is 5->10->15->20->25 and we add an item 30 at the end, then the Linked List becomes 5->10-
>15->20->25->30. Since a Linked List is typically represented by the head of it, we have to traverse the
list till the end and then change the next to last node to a new node.

You might also like