



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
An overview of singly linked lists, their definition, creation process, and basic operations. It covers insertion and deletion at the beginning, end, and after a specified node, as well as displaying and searching for elements. It also includes code snippets for creating a node and inserting it into a list.
Typology: Summaries
1 / 5
This page cannot be seen from the preview
Don't miss anything!




Lapuz, Jam Chester S. DSA – LEC BSCS 1- 2 Mr. Regala, Richard
Singly linked list can be defined as the collection of ordered set of elements. The number of elements may vary according to need of the program. A node in the singly linked list consist of two parts: data part and link part. Data part of the node stores actual information that is to be represented by the node while the link part of the node stores the address of its immediate successor. Creation of the node: Basic Operations Following are the basic operations supported by a list. Insertion − Adds an element at the beginning of the list. Deletion − Deletes an element at the beginning of the list. Display − Displays the complete list. Search − Searches an element using the given key. Delete − Deletes an element using the given key.
Insertion: Insertion at beginning: Inserting any element at the front of the list. We just need to a few link adjustments to make the new node as the head of the list. Insertion at end of the list: It involves insertion at the last of the linked list. The new node can be inserted as the only node in the list or it can be inserted as the last one. Insertion after specified node: It involves insertion after the specified node of the linked list. We need to skip the desired number of nodes in order to reach the node after which the new node will be inserted. Imagine that we are inserting a node B (NewNode), between A (LeftNode) and C (RightNode). Then point B.next to C – [NewNode.next −> RightNode;]
First, locate the target node to be removed, by using searching algorithms. The left (previous) node of the target node now should point to the next node of the target node [LeftNode.next −> TargetNode.next;] This will remove the link that was pointing to the target node. Now, using the following code, we will remove what the target node is pointing at. [TargetNode.next −> NULL;] We need to use the deleted node. We can keep that in memory otherwise we can simply deallocate memory and wipe off the target node completely.