Deletion from single way
linked list and search
PRESENTED BY:
M D I S L A M K H A N 171-15-9537
A B D U L L A H A L R E D WA N 171-15-9538
A S I Q U R R A H M A N A S I Q 171-15-9528
M O M I N U R I S L A M A S A D 163-15-8523
Linked list
linked list is a linear data structure. It contains
nodes. Each node contains two parts,
i.e. DATA part and LINK part.
 The data contains elements , and
 Link contains address of another node.
WHAT ARE LINKED LISTS
A linked list is a linear data
structure.
Nodes make up linked lists.
Nodes are structures made up of
data and a pointer to another
node.
 Usually the pointer is called
next.
TYPES OF LINKED LISTS
1. Single linked list.
2. Double linked list.
3. Circular linked list.
4. Circular double linked list.
Singly Linked List
 Each node has only one link part.
Each link part contains the address of the next node in
the list.
Link part of the last node contains NULL value which
signifies the end of the node.
BASIC OPERATIONS ON A LIST
 Creating a List
 Inserting an element in a list
 Deleting an element from a list
 Searching a list
 Reversing a list
Deleting a Node in SLL
Here also we have three cases:-
Deleting the first node
Deleting the last node
Deleting the intermediate node
DELETING THE FIRST NODE
Here we apply 2 steps:-
 Making the start pointer point towards the 2nd node.
Deleting the first node using delete keyword.
void delete_from_first()
{
struct node* temp=head;
head=head->next/temp->next;
free(temp);
}
Deleting the last node
Here we apply 2 steps:-
 Making the second last node’s next pointer point to NULL.
 Deleting the last node via delete keyword.
void delete_from_last()
{
struct node *temp=head, *temp2;
while(temp->next)
{
temp2=temp;
temp=temp->next;
}
temp2->next=NULL;
free(temp);
}
Deleting a particular node
Here we make the next pointer of the node previous to the node
being deleted ,point to the successor node of the node to be
deleted and then delete the node using. delete keyword.
void delete_from_any_position(int pos)
{
int i ;
struct node *temp=head, *temp2;
for(i=2 ; i<pos ; i++)
{
temp=temp->next;
}
temp2=temp->next
temp->next=temp2->next;
free(temp2);
}
Searching a SLL
 Searching involves finding the required element in the list.
 We can use various techniques of searching like linear search or
binary search where binary search is more efficient in case of
Arrays.
 But in case of linked list since random access is not available it
would become complex to do binary search in it.
 We can perform simple linear search traversal.
 In linear search each node is traversed till the data in
the node matches with the required value:
void search (int x)
{
node*temp=start;
while(temp!=NULL)
{
if(temp->data==x)
{
cout<<“FOUND ”<<temp->data;
break;
}
temp=temp->next;
}
APPLICATIONS OF LINKED LIST
A linked list is a very efficient data structure for sorted list
that will go through many insertions and deletions.
A linked list is a dynamic data structure in which the list
can start with no nodes and then grow as new nodes are
needed. A node can be easily deleted without moving other
nodes, as would be the case with an array.
For example, a linked list could be used to hold the records
of students in a school. Each quarter or semester , new
students enroll in the school and some students leave or
graduate.
 Advantages of using a Linked list:
Save space (don’t have to worry about sparse polynomials) and
easy to maintain.
 Don’t need to allocate list size and can declare nodes (terms) only
as needed.
Operation related to data elements like insertions or deletion are
more simplified
 Disadvantages of using a Linked list :
 Can’t go backwards through the list.
 Can’t jump to the beginning of the list from the end.
Deletion from single way linked list and search

Deletion from single way linked list and search

  • 1.
    Deletion from singleway linked list and search PRESENTED BY: M D I S L A M K H A N 171-15-9537 A B D U L L A H A L R E D WA N 171-15-9538 A S I Q U R R A H M A N A S I Q 171-15-9528 M O M I N U R I S L A M A S A D 163-15-8523
  • 2.
    Linked list linked listis a linear data structure. It contains nodes. Each node contains two parts, i.e. DATA part and LINK part.  The data contains elements , and  Link contains address of another node.
  • 3.
    WHAT ARE LINKEDLISTS A linked list is a linear data structure. Nodes make up linked lists. Nodes are structures made up of data and a pointer to another node.  Usually the pointer is called next.
  • 4.
    TYPES OF LINKEDLISTS 1. Single linked list. 2. Double linked list. 3. Circular linked list. 4. Circular double linked list.
  • 5.
    Singly Linked List Each node has only one link part. Each link part contains the address of the next node in the list. Link part of the last node contains NULL value which signifies the end of the node.
  • 6.
    BASIC OPERATIONS ONA LIST  Creating a List  Inserting an element in a list  Deleting an element from a list  Searching a list  Reversing a list
  • 7.
    Deleting a Nodein SLL Here also we have three cases:- Deleting the first node Deleting the last node Deleting the intermediate node
  • 8.
    DELETING THE FIRSTNODE Here we apply 2 steps:-  Making the start pointer point towards the 2nd node. Deleting the first node using delete keyword.
  • 9.
    void delete_from_first() { struct node*temp=head; head=head->next/temp->next; free(temp); }
  • 10.
    Deleting the lastnode Here we apply 2 steps:-  Making the second last node’s next pointer point to NULL.  Deleting the last node via delete keyword.
  • 11.
    void delete_from_last() { struct node*temp=head, *temp2; while(temp->next) { temp2=temp; temp=temp->next; } temp2->next=NULL; free(temp); }
  • 12.
    Deleting a particularnode Here we make the next pointer of the node previous to the node being deleted ,point to the successor node of the node to be deleted and then delete the node using. delete keyword.
  • 13.
    void delete_from_any_position(int pos) { inti ; struct node *temp=head, *temp2; for(i=2 ; i<pos ; i++) { temp=temp->next; } temp2=temp->next temp->next=temp2->next; free(temp2); }
  • 14.
    Searching a SLL Searching involves finding the required element in the list.  We can use various techniques of searching like linear search or binary search where binary search is more efficient in case of Arrays.  But in case of linked list since random access is not available it would become complex to do binary search in it.  We can perform simple linear search traversal.
  • 15.
     In linearsearch each node is traversed till the data in the node matches with the required value: void search (int x) { node*temp=start; while(temp!=NULL) { if(temp->data==x) { cout<<“FOUND ”<<temp->data; break; } temp=temp->next; }
  • 16.
    APPLICATIONS OF LINKEDLIST A linked list is a very efficient data structure for sorted list that will go through many insertions and deletions. A linked list is a dynamic data structure in which the list can start with no nodes and then grow as new nodes are needed. A node can be easily deleted without moving other nodes, as would be the case with an array. For example, a linked list could be used to hold the records of students in a school. Each quarter or semester , new students enroll in the school and some students leave or graduate.
  • 17.
     Advantages ofusing a Linked list: Save space (don’t have to worry about sparse polynomials) and easy to maintain.  Don’t need to allocate list size and can declare nodes (terms) only as needed. Operation related to data elements like insertions or deletion are more simplified  Disadvantages of using a Linked list :  Can’t go backwards through the list.  Can’t jump to the beginning of the list from the end.