SlideShare a Scribd company logo
1 of 22
Linked List
 Linked List can be defined as collection of objects called nodes that are
randomly stored in the memory.
 A node contains two fields i.e. data stored at that particular address and the
pointer which contains the address of the next node in the memory.
 The last node of the list contains pointer to the null.
Uses of Linked List
• The list is not required to be contiguously present in the memory. The node
can reside any where in the memory and linked together to make a list. This
achieves optimized utilization of space.
• list size is limited to the memory size and doesn't need to be declared in
advance.
• Empty node can not be present in the linked list.
• We can store values of primitive types or objects in the singly linked list.
Node Creation :
struct node
{
int data;
struct node *next;
};
struct node *head, *ptr;
ptr = (struct node *)malloc(sizeof(struct node *));
Insertion in Linked list
SN Operation Description
1 Insertion at beginning It involves 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.
2 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. Different logics are
implemented in each scenario.
3 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. .
Insertion at the Beginning
struct node *ptr;
int item;
ptr = (struct node *)
malloc(sizeof(struct node *));
if(ptr == NULL)
{
printf("nOVERFLOW");
}
else
{
printf("nEnter valuen");
scanf("%d",&item);
ptr->data = item;
ptr->next = head;
head = ptr;
printf("nNode inserted");
}
Insertion At Last
struct node *ptr,*temp;
int item;
ptr = (struct
node*)malloc(sizeof(struct node));
if(ptr == NULL)
{
printf("nOVERFLOW");
}
else
{
printf("nEnter value?n");
scanf("%d",&item);
ptr->data = item;
if(head == NULL)
{
ptr -> next = NULL;
head = ptr;
printf("nNode inserted");
}
else
{
temp = head;
while (temp -> next != NULL)
{
temp = temp -> next;
}
temp->next = ptr;
ptr->next = NULL;
printf("nNode inserted");
}
}
}
Random Insert at Position
int i,loc,item;
struct node *ptr, *temp;
ptr = (struct node *) malloc (sizeof(struct node));
if(ptr == NULL)
{
printf("nOVERFLOW");
}
else
{
printf("nEnter element value");
scanf("%d",&item);
ptr->data = item;
printf("nEnter the location after which you want to insert ");
scanf("n%d",&loc);
temp=head;
for(i=0;i<loc;i++)
{
temp = temp->next;
if(temp == NULL)
{
printf("ncan't insertn");
return;
}
}
ptr ->next = temp ->next;
temp ->next = ptr;
printf("nNode inserted");
}
Begin Delete
struct node *ptr;
if(head == NULL)
{
printf("nList is emptyn");
}
else
{
ptr = head;
head = ptr->next;
free(ptr);
printf("nNode deleted from the begining ...n");
}
Delete Last node
struct node *ptr,*ptr1;
if(head == NULL)
{
printf("nlist is empty");
}
else if(head -> next == NULL)
{
head = NULL;
free(head);
printf("nOnly node of the list deleted ...n");
}
else
{
ptr = head;
while(ptr->next != NULL)
{
ptr1 = ptr;
ptr = ptr ->next;
}
ptr1->next = NULL;
free(ptr);
printf("nDeleted Node from the last ...n");
}
Random Delete node at Position
struct node *ptr,*ptr1;
int loc,i;
printf("n Enter the location of the node after which you want to perform deletion n");
scanf("%d",&loc);
ptr=head;
for(i=0;i<loc;i++)
{
ptr1 = ptr;
ptr = ptr->next;
if(ptr == NULL)
{
printf("nCan't delete");
return;
}
}
ptr1 ->next = ptr ->next;
free(ptr);
printf("nDeleted node %d ",loc+1);
Find node in Linked List
struct node *ptr;
int item,i=0,flag;
ptr = head;
if(ptr == NULL)
{
printf("nEmpty Listn");
}
else
{
printf("nEnter item which you want to
search?n");
scanf("%d",&item);
while (ptr!=NULL)
{
if(ptr->data == item)
{
printf("item found at location %d
",i+1);
flag=0;
}
else
{
flag=1;
}
i++;
ptr = ptr -> next;
}
if(flag==1)
{
printf("Item not foundn");
}
}
Display Linked List
struct node *ptr;
ptr = head;
if(ptr == NULL)
{
printf("Nothing to print");
}
else
{
printf("nprinting values . . . . .n");
while (ptr!=NULL)
{
printf("n%d",ptr->data);
ptr = ptr -> next;
}
}
DOUBLY LINKED LIST
What is a doubly-linked list?
A doubly linked list is another type of the linked list. It is called a doubly linked list because it
contains two addresses while a singly linked list contains a single address. It is a list that has
total three parts, one is a data part, and others two are the pointers, i.e., previous and next.
The previous pointer holds the address of the previous node, and the next pointer holds the
address of the next node. Therefore, we can say that list has two references, i.e., forward and
backward reference to traverse in either direction.
In c the structure of a node is describe as :
struct node
{
struct node *prev;
int data;
struct node *next;
}
 Memory Representation of a doubly linked list is shown in the following image.
Generally, doubly linked list consumes more space for every node and therefore,
causes more expansive basic operations such as insertion and deletion. However, we
can easily manipulate the elements of the list since the list maintains pointers in both
the directions (forward and backward).
 In the following image, the first element of the list that is i.e. 13 stored at address 1.
The head pointer points to the starting address 1. Since this is the first element being
added to the list therefore the prev of the list contains null. The next node of the list
resides at address 4 therefore the first node contains 4 in its next pointer.
 We can traverse the list in this way until we find any node containing null or -1 in its
next part.
MEMORY REPRESENTATION OF A DOUBLY LINKED
LIST
Insert at Begining
struct node *ptr;
int item;
ptr = (struct node *)malloc(sizeof(struct node));
if(ptr == NULL)
{
printf("nOVERFLOW");
}
else
{
printf("nEnter Item value");
scanf("%d",&item);
if(head==NULL)
{
ptr->next = NULL;
ptr->prev=NULL;
ptr->data=item;
head=ptr;
}
else
{
ptr->data=item;
ptr->prev=NULL;
ptr->next = head;
head->prev=ptr;
head=ptr;
}
printf("nNode insertedn");
}
Insert at Last
struct node *ptr,*temp;
int item;
ptr = (struct node *) malloc(sizeof(struct node));
if(ptr == NULL)
{
printf("nOVERFLOW");
}
else
{
printf("nEnter value");
scanf("%d",&item);
ptr->data=item;
if(head == NULL)
{
ptr->next = NULL;
ptr->prev = NULL;
head = ptr;
}
else
{
temp = head;
while(temp->next!=NULL)
{
temp = temp->next;
}
temp->next = ptr;
ptr ->prev=temp;
ptr->next = NULL;
}
}
printf("nnode insertedn");
Insert at Position
struct node *ptr,*temp;
int item,loc,i;
ptr = (struct node *)malloc(sizeof(struct node));
if(ptr == NULL)
{
printf("n OVERFLOW");
}
else
{
temp=head;
printf("Enter the location");
scanf("%d",&loc);
for(i=1;i<loc-1; i++)
{
temp = temp->next;
if(temp == NULL)
{
printf("n There are less than %d elements", loc);
return;
}
}
printf("Enter value");
scanf("%d",&ptr->data);
ptr -> prev = temp;
ptr->next = temp->next;
temp->next = ptr;
temp->next->prev=ptr;
printf("nnode insertedn");
}
Deletion at Begining
struct node *ptr;
if(head == NULL)
{
printf("n UNDERFLOW");
}
else if(head->next == NULL)
{
head = NULL;
free(head);
printf("n node deletedn");
}
else
{
ptr = head;
head = head -> next;
head -> prev = NULL;
free(ptr);
printf("nnode deletedn");
}
Deletion at last
struct node *ptr;
if(head == NULL)
{
printf("n UNDERFLOW");
}
else if(head->next == NULL)
{
head = NULL;
free(head);
printf("nnode deletedn");
}
else
{
ptr = head;
if(ptr->next != NULL)
{
ptr = ptr -> next;
}
ptr -> prev -> next = NULL;
free(ptr);
printf("nnode deletedn");
}
Deletion at Position
struct node *ptr, *temp;
int val;
printf("n Enter the data after which the node is to be del
eted : ");
scanf("%d", &val);
ptr = head;
while(ptr -> data != val)
ptr = ptr -> next;
if(ptr -> next == NULL)
{
printf("nCan't deleten");
}
else if(ptr -> next -> next == NULL)
{
ptr ->next = NULL;
}
else
{
temp = ptr -> next;
ptr -> next = temp -> next;
temp -> next -> prev = ptr;
free(temp);
printf("nnode deletedn");
}
CIRCULAR LINKED LIST
 In a circular Singly linked list, the last node of the list contains a pointer to the
first node of the list. We can have circular singly linked list as well as circular
doubly linked list.
 We traverse a circular singly linked list until we reach the same node where we
started. The circular singly liked list has no beginning and no ending. There is no
null value present in the next part of any of the nodes.
 The following image shows a circular singly linked list.
Begin Insert
struct node *ptr,*temp;
int item;
ptr = (struct node *)malloc(sizeof(struct node));
if(ptr == NULL)
{
printf("nOVERFLOW");
}
else
{
printf("nEnter the node data?");
scanf("%d",&item);
ptr -> data = item;
if(head == NULL)
{
head = ptr;
ptr -> next = head;
}
else
{
temp = head;
while(temp->next != head)
temp = temp->next;
ptr->next = head;
temp -> next = ptr;
head = ptr;
}
printf("nnode insertedn");
}
Last Insert
struct node *ptr,*temp;
int item;
ptr = (struct node *)malloc(sizeof(struct node));
if(ptr == NULL)
{
printf("nOVERFLOWn");
}
else
{
printf("nEnter Data?");
scanf("%d",&item);
ptr->data = item;
if(head == NULL)
{
head = ptr;
ptr -> next = head;
}
else
{
temp = head;
while(temp -> next != head)
{
temp = temp -> next;
}
temp -> next = ptr;
ptr -> next = head;
}
printf("nnode insertedn");
}
Begin Delete
struct node *ptr;
if(head == NULL)
{
printf("nUNDERFLOW");
}
else if(head->next == head)
{
head = NULL;
free(head);
printf("nnode deletedn");
}
else
{ ptr = head;
while(ptr -> next != head)
ptr = ptr -> next;
ptr->next = head->next;
free(head);
head = ptr->next;
printf("nnode deletedn");
}
Last Delete
struct node *ptr, *preptr;
if(head==NULL)
{
printf("nUNDERFLOW");
}
else if (head ->next == head)
{
head = NULL;
free(head);
printf("nnode deletedn");
}
else
{
ptr = head;
while(ptr ->next != head)
{
preptr=ptr;
ptr = ptr->next;
}
preptr->next = ptr -> next;
free(ptr);
printf("nnode deletedn");
}
Search node
struct node *ptr;
int item,i=0,flag=1;
ptr = head;
if(ptr == NULL)
{
printf("nEmpty Listn");
}
else
{
printf("nEnter item which you want to
search?n");
scanf("%d",&item);
if(head ->data == item)
{
printf("item found at location %d",i+1);
flag=0;
}
else
{
while (ptr->next != head)
{
if(ptr->data == item)
{
printf("item found at location %d
",i+1);
flag=0;
break;
}
else
{
flag=1;
}
i++;
ptr = ptr -> next;
}
}
if(flag != 0)
{
printf("Item not foundn");
}
}
Display linked list
struct node *ptr;
ptr=head;
if(head == NULL)
{
printf("nnothing to print");
}
else
{
printf("n printing values ... n");
while(ptr -> next != head)
{
printf("%dn", ptr -> data);
ptr = ptr -> next;
}
printf("%dn", ptr -> data);
}
Dynamic memory allocation in C
The concept of dynamic memory allocation in c language
enables the C programmer to allocate memory at runtime.
Dynamic memory allocation in c language is possible by 4
functions of stdlib.h header file.
malloc()
calloc()
realloc()
free()
Before learning above functions, let's understand the difference
between static memory allocation and dynamic memory
allocation.
static memory allocation dynamic memory allocation
memory is allocated at compile
time.
memory is allocated at run
time.
memory can't be increased
while executing program.
memory can be increased
while executing program.
used in array. used in linked list.
malloc() allocates single block of
requested memory.
calloc() allocates multiple block of
requested memory.
realloc() reallocates the memory
occupied by malloc() or
calloc() functions.
free() frees the dynamically allocated
memory.
malloc
ptr=(cast-type*)malloc(byte-size)
Calloc
ptr=(cast-t ype*)calloc(number, byte-size)
 The calloc() function allocates multiple block of requested
memory.
 It initially initialize all bytes to zero.
 It returns NULL if memory is not sufficient.

More Related Content

Similar to Ll.pptx

Data Structures in C++I am really new to C++, so links are really .pdf
Data Structures in C++I am really new to C++, so links are really .pdfData Structures in C++I am really new to C++, so links are really .pdf
Data Structures in C++I am really new to C++, so links are really .pdfrohit219406
 
Linked list and its operations - Traversal
Linked list and its operations - TraversalLinked list and its operations - Traversal
Linked list and its operations - Traversalkasthurimukila
 
–PLS write program in c++Recursive Linked List OperationsWrite a.pdf
–PLS write program in c++Recursive Linked List OperationsWrite a.pdf–PLS write program in c++Recursive Linked List OperationsWrite a.pdf
–PLS write program in c++Recursive Linked List OperationsWrite a.pdfpasqualealvarez467
 
What is Linked List in C.docx
What is Linked List in C.docxWhat is Linked List in C.docx
What is Linked List in C.docxnona800027
 
DS_LinkedList.pptx
DS_LinkedList.pptxDS_LinkedList.pptx
DS_LinkedList.pptxmsohail37
 
in C++ , Design a linked list class named IntegerList to hold a seri.pdf
in C++ , Design a linked list class named IntegerList to hold a seri.pdfin C++ , Design a linked list class named IntegerList to hold a seri.pdf
in C++ , Design a linked list class named IntegerList to hold a seri.pdfeyewaregallery
 
The LinkedList1 class implements a Linked list. class.pdf
The LinkedList1 class implements a Linked list. class.pdfThe LinkedList1 class implements a Linked list. class.pdf
The LinkedList1 class implements a Linked list. class.pdfmalavshah9013
 
DS Module 03.pdf
DS Module 03.pdfDS Module 03.pdf
DS Module 03.pdfSonaPathak5
 
C++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdf
C++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdfC++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdf
C++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdfpoblettesedanoree498
 

Similar to Ll.pptx (20)

Data Structures in C++I am really new to C++, so links are really .pdf
Data Structures in C++I am really new to C++, so links are really .pdfData Structures in C++I am really new to C++, so links are really .pdf
Data Structures in C++I am really new to C++, so links are really .pdf
 
Data structure
Data  structureData  structure
Data structure
 
Linked list and its operations - Traversal
Linked list and its operations - TraversalLinked list and its operations - Traversal
Linked list and its operations - Traversal
 
Adt of lists
Adt of listsAdt of lists
Adt of lists
 
Linear data structure concepts
Linear data structure conceptsLinear data structure concepts
Linear data structure concepts
 
dynamicList.ppt
dynamicList.pptdynamicList.ppt
dynamicList.ppt
 
17 linkedlist (1)
17 linkedlist (1)17 linkedlist (1)
17 linkedlist (1)
 
Linkedlist
LinkedlistLinkedlist
Linkedlist
 
–PLS write program in c++Recursive Linked List OperationsWrite a.pdf
–PLS write program in c++Recursive Linked List OperationsWrite a.pdf–PLS write program in c++Recursive Linked List OperationsWrite a.pdf
–PLS write program in c++Recursive Linked List OperationsWrite a.pdf
 
Linked list
Linked listLinked list
Linked list
 
What is Linked List in C.docx
What is Linked List in C.docxWhat is Linked List in C.docx
What is Linked List in C.docx
 
DS_LinkedList.pptx
DS_LinkedList.pptxDS_LinkedList.pptx
DS_LinkedList.pptx
 
Chapter14
Chapter14Chapter14
Chapter14
 
in C++ , Design a linked list class named IntegerList to hold a seri.pdf
in C++ , Design a linked list class named IntegerList to hold a seri.pdfin C++ , Design a linked list class named IntegerList to hold a seri.pdf
in C++ , Design a linked list class named IntegerList to hold a seri.pdf
 
The LinkedList1 class implements a Linked list. class.pdf
The LinkedList1 class implements a Linked list. class.pdfThe LinkedList1 class implements a Linked list. class.pdf
The LinkedList1 class implements a Linked list. class.pdf
 
Team 10
Team 10Team 10
Team 10
 
DS Module 03.pdf
DS Module 03.pdfDS Module 03.pdf
DS Module 03.pdf
 
DSA(1).pptx
DSA(1).pptxDSA(1).pptx
DSA(1).pptx
 
Linked list
Linked list Linked list
Linked list
 
C++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdf
C++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdfC++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdf
C++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdf
 

Recently uploaded

Untitled presedddddddddddddddddntation (1).pptx
Untitled presedddddddddddddddddntation (1).pptxUntitled presedddddddddddddddddntation (1).pptx
Untitled presedddddddddddddddddntation (1).pptxmapanig881
 
办理学位证(SFU证书)西蒙菲莎大学毕业证成绩单原版一比一
办理学位证(SFU证书)西蒙菲莎大学毕业证成绩单原版一比一办理学位证(SFU证书)西蒙菲莎大学毕业证成绩单原版一比一
办理学位证(SFU证书)西蒙菲莎大学毕业证成绩单原版一比一F dds
 
Design Portfolio - 2024 - William Vickery
Design Portfolio - 2024 - William VickeryDesign Portfolio - 2024 - William Vickery
Design Portfolio - 2024 - William VickeryWilliamVickery6
 
PORTAFOLIO 2024_ ANASTASIYA KUDINOVA
PORTAFOLIO   2024_  ANASTASIYA  KUDINOVAPORTAFOLIO   2024_  ANASTASIYA  KUDINOVA
PORTAFOLIO 2024_ ANASTASIYA KUDINOVAAnastasiya Kudinova
 
Kindergarten Assessment Questions Via LessonUp
Kindergarten Assessment Questions Via LessonUpKindergarten Assessment Questions Via LessonUp
Kindergarten Assessment Questions Via LessonUpmainac1
 
How to Be Famous in your Field just visit our Site
How to Be Famous in your Field just visit our SiteHow to Be Famous in your Field just visit our Site
How to Be Famous in your Field just visit our Sitegalleryaagency
 
NATA 2024 SYLLABUS, full syllabus explained in detail
NATA 2024 SYLLABUS, full syllabus explained in detailNATA 2024 SYLLABUS, full syllabus explained in detail
NATA 2024 SYLLABUS, full syllabus explained in detailDesigntroIntroducing
 
call girls in Harsh Vihar (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Harsh Vihar (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Harsh Vihar (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Harsh Vihar (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Call Girls In Safdarjung Enclave 24/7✡️9711147426✡️ Escorts Service
Call Girls In Safdarjung Enclave 24/7✡️9711147426✡️ Escorts ServiceCall Girls In Safdarjung Enclave 24/7✡️9711147426✡️ Escorts Service
Call Girls In Safdarjung Enclave 24/7✡️9711147426✡️ Escorts Servicejennyeacort
 
VIP Call Girl Amravati Aashi 8250192130 Independent Escort Service Amravati
VIP Call Girl Amravati Aashi 8250192130 Independent Escort Service AmravatiVIP Call Girl Amravati Aashi 8250192130 Independent Escort Service Amravati
VIP Call Girl Amravati Aashi 8250192130 Independent Escort Service AmravatiSuhani Kapoor
 
Call Girls Meghani Nagar 7397865700 Independent Call Girls
Call Girls Meghani Nagar 7397865700  Independent Call GirlsCall Girls Meghani Nagar 7397865700  Independent Call Girls
Call Girls Meghani Nagar 7397865700 Independent Call Girlsssuser7cb4ff
 
Call Girls Satellite 7397865700 Ridhima Hire Me Full Night
Call Girls Satellite 7397865700 Ridhima Hire Me Full NightCall Girls Satellite 7397865700 Ridhima Hire Me Full Night
Call Girls Satellite 7397865700 Ridhima Hire Me Full Nightssuser7cb4ff
 
VIP Call Girls Service Mehdipatnam Hyderabad Call +91-8250192130
VIP Call Girls Service Mehdipatnam Hyderabad Call +91-8250192130VIP Call Girls Service Mehdipatnam Hyderabad Call +91-8250192130
VIP Call Girls Service Mehdipatnam Hyderabad Call +91-8250192130Suhani Kapoor
 
(办理学位证)埃迪斯科文大学毕业证成绩单原版一比一
(办理学位证)埃迪斯科文大学毕业证成绩单原版一比一(办理学位证)埃迪斯科文大学毕业证成绩单原版一比一
(办理学位证)埃迪斯科文大学毕业证成绩单原版一比一Fi sss
 
Call In girls Bhikaji Cama Place 🔝 ⇛8377877756 FULL Enjoy Delhi NCR
Call In girls Bhikaji Cama Place 🔝 ⇛8377877756 FULL Enjoy Delhi NCRCall In girls Bhikaji Cama Place 🔝 ⇛8377877756 FULL Enjoy Delhi NCR
Call In girls Bhikaji Cama Place 🔝 ⇛8377877756 FULL Enjoy Delhi NCRdollysharma2066
 
2024新版美国旧金山州立大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degree
2024新版美国旧金山州立大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degree2024新版美国旧金山州立大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degree
2024新版美国旧金山州立大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degreeyuu sss
 
办理学位证(NUS证书)新加坡国立大学毕业证成绩单原版一比一
办理学位证(NUS证书)新加坡国立大学毕业证成绩单原版一比一办理学位证(NUS证书)新加坡国立大学毕业证成绩单原版一比一
办理学位证(NUS证书)新加坡国立大学毕业证成绩单原版一比一Fi L
 
Call Girls Aslali 7397865700 Ridhima Hire Me Full Night
Call Girls Aslali 7397865700 Ridhima Hire Me Full NightCall Girls Aslali 7397865700 Ridhima Hire Me Full Night
Call Girls Aslali 7397865700 Ridhima Hire Me Full Nightssuser7cb4ff
 
Revit Understanding Reference Planes and Reference lines in Revit for Family ...
Revit Understanding Reference Planes and Reference lines in Revit for Family ...Revit Understanding Reference Planes and Reference lines in Revit for Family ...
Revit Understanding Reference Planes and Reference lines in Revit for Family ...Narsimha murthy
 

Recently uploaded (20)

Untitled presedddddddddddddddddntation (1).pptx
Untitled presedddddddddddddddddntation (1).pptxUntitled presedddddddddddddddddntation (1).pptx
Untitled presedddddddddddddddddntation (1).pptx
 
办理学位证(SFU证书)西蒙菲莎大学毕业证成绩单原版一比一
办理学位证(SFU证书)西蒙菲莎大学毕业证成绩单原版一比一办理学位证(SFU证书)西蒙菲莎大学毕业证成绩单原版一比一
办理学位证(SFU证书)西蒙菲莎大学毕业证成绩单原版一比一
 
Design Portfolio - 2024 - William Vickery
Design Portfolio - 2024 - William VickeryDesign Portfolio - 2024 - William Vickery
Design Portfolio - 2024 - William Vickery
 
PORTAFOLIO 2024_ ANASTASIYA KUDINOVA
PORTAFOLIO   2024_  ANASTASIYA  KUDINOVAPORTAFOLIO   2024_  ANASTASIYA  KUDINOVA
PORTAFOLIO 2024_ ANASTASIYA KUDINOVA
 
Kindergarten Assessment Questions Via LessonUp
Kindergarten Assessment Questions Via LessonUpKindergarten Assessment Questions Via LessonUp
Kindergarten Assessment Questions Via LessonUp
 
How to Be Famous in your Field just visit our Site
How to Be Famous in your Field just visit our SiteHow to Be Famous in your Field just visit our Site
How to Be Famous in your Field just visit our Site
 
NATA 2024 SYLLABUS, full syllabus explained in detail
NATA 2024 SYLLABUS, full syllabus explained in detailNATA 2024 SYLLABUS, full syllabus explained in detail
NATA 2024 SYLLABUS, full syllabus explained in detail
 
Cheap Rate Call girls Kalkaji 9205541914 shot 1500 night
Cheap Rate Call girls Kalkaji 9205541914 shot 1500 nightCheap Rate Call girls Kalkaji 9205541914 shot 1500 night
Cheap Rate Call girls Kalkaji 9205541914 shot 1500 night
 
call girls in Harsh Vihar (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Harsh Vihar (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Harsh Vihar (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Harsh Vihar (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
Call Girls In Safdarjung Enclave 24/7✡️9711147426✡️ Escorts Service
Call Girls In Safdarjung Enclave 24/7✡️9711147426✡️ Escorts ServiceCall Girls In Safdarjung Enclave 24/7✡️9711147426✡️ Escorts Service
Call Girls In Safdarjung Enclave 24/7✡️9711147426✡️ Escorts Service
 
VIP Call Girl Amravati Aashi 8250192130 Independent Escort Service Amravati
VIP Call Girl Amravati Aashi 8250192130 Independent Escort Service AmravatiVIP Call Girl Amravati Aashi 8250192130 Independent Escort Service Amravati
VIP Call Girl Amravati Aashi 8250192130 Independent Escort Service Amravati
 
Call Girls Meghani Nagar 7397865700 Independent Call Girls
Call Girls Meghani Nagar 7397865700  Independent Call GirlsCall Girls Meghani Nagar 7397865700  Independent Call Girls
Call Girls Meghani Nagar 7397865700 Independent Call Girls
 
Call Girls Satellite 7397865700 Ridhima Hire Me Full Night
Call Girls Satellite 7397865700 Ridhima Hire Me Full NightCall Girls Satellite 7397865700 Ridhima Hire Me Full Night
Call Girls Satellite 7397865700 Ridhima Hire Me Full Night
 
VIP Call Girls Service Mehdipatnam Hyderabad Call +91-8250192130
VIP Call Girls Service Mehdipatnam Hyderabad Call +91-8250192130VIP Call Girls Service Mehdipatnam Hyderabad Call +91-8250192130
VIP Call Girls Service Mehdipatnam Hyderabad Call +91-8250192130
 
(办理学位证)埃迪斯科文大学毕业证成绩单原版一比一
(办理学位证)埃迪斯科文大学毕业证成绩单原版一比一(办理学位证)埃迪斯科文大学毕业证成绩单原版一比一
(办理学位证)埃迪斯科文大学毕业证成绩单原版一比一
 
Call In girls Bhikaji Cama Place 🔝 ⇛8377877756 FULL Enjoy Delhi NCR
Call In girls Bhikaji Cama Place 🔝 ⇛8377877756 FULL Enjoy Delhi NCRCall In girls Bhikaji Cama Place 🔝 ⇛8377877756 FULL Enjoy Delhi NCR
Call In girls Bhikaji Cama Place 🔝 ⇛8377877756 FULL Enjoy Delhi NCR
 
2024新版美国旧金山州立大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degree
2024新版美国旧金山州立大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degree2024新版美国旧金山州立大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degree
2024新版美国旧金山州立大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degree
 
办理学位证(NUS证书)新加坡国立大学毕业证成绩单原版一比一
办理学位证(NUS证书)新加坡国立大学毕业证成绩单原版一比一办理学位证(NUS证书)新加坡国立大学毕业证成绩单原版一比一
办理学位证(NUS证书)新加坡国立大学毕业证成绩单原版一比一
 
Call Girls Aslali 7397865700 Ridhima Hire Me Full Night
Call Girls Aslali 7397865700 Ridhima Hire Me Full NightCall Girls Aslali 7397865700 Ridhima Hire Me Full Night
Call Girls Aslali 7397865700 Ridhima Hire Me Full Night
 
Revit Understanding Reference Planes and Reference lines in Revit for Family ...
Revit Understanding Reference Planes and Reference lines in Revit for Family ...Revit Understanding Reference Planes and Reference lines in Revit for Family ...
Revit Understanding Reference Planes and Reference lines in Revit for Family ...
 

Ll.pptx

  • 1.
  • 2. Linked List  Linked List can be defined as collection of objects called nodes that are randomly stored in the memory.  A node contains two fields i.e. data stored at that particular address and the pointer which contains the address of the next node in the memory.  The last node of the list contains pointer to the null. Uses of Linked List • The list is not required to be contiguously present in the memory. The node can reside any where in the memory and linked together to make a list. This achieves optimized utilization of space. • list size is limited to the memory size and doesn't need to be declared in advance. • Empty node can not be present in the linked list. • We can store values of primitive types or objects in the singly linked list.
  • 3. Node Creation : struct node { int data; struct node *next; }; struct node *head, *ptr; ptr = (struct node *)malloc(sizeof(struct node *)); Insertion in Linked list SN Operation Description 1 Insertion at beginning It involves 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. 2 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. Different logics are implemented in each scenario. 3 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. .
  • 4. Insertion at the Beginning struct node *ptr; int item; ptr = (struct node *) malloc(sizeof(struct node *)); if(ptr == NULL) { printf("nOVERFLOW"); } else { printf("nEnter valuen"); scanf("%d",&item); ptr->data = item; ptr->next = head; head = ptr; printf("nNode inserted"); } Insertion At Last struct node *ptr,*temp; int item; ptr = (struct node*)malloc(sizeof(struct node)); if(ptr == NULL) { printf("nOVERFLOW"); } else { printf("nEnter value?n"); scanf("%d",&item); ptr->data = item; if(head == NULL) { ptr -> next = NULL; head = ptr; printf("nNode inserted"); } else { temp = head; while (temp -> next != NULL) { temp = temp -> next; } temp->next = ptr; ptr->next = NULL; printf("nNode inserted"); } } }
  • 5. Random Insert at Position int i,loc,item; struct node *ptr, *temp; ptr = (struct node *) malloc (sizeof(struct node)); if(ptr == NULL) { printf("nOVERFLOW"); } else { printf("nEnter element value"); scanf("%d",&item); ptr->data = item; printf("nEnter the location after which you want to insert "); scanf("n%d",&loc); temp=head; for(i=0;i<loc;i++) { temp = temp->next; if(temp == NULL) { printf("ncan't insertn"); return; } } ptr ->next = temp ->next; temp ->next = ptr; printf("nNode inserted"); }
  • 6. Begin Delete struct node *ptr; if(head == NULL) { printf("nList is emptyn"); } else { ptr = head; head = ptr->next; free(ptr); printf("nNode deleted from the begining ...n"); } Delete Last node struct node *ptr,*ptr1; if(head == NULL) { printf("nlist is empty"); } else if(head -> next == NULL) { head = NULL; free(head); printf("nOnly node of the list deleted ...n"); } else { ptr = head; while(ptr->next != NULL) { ptr1 = ptr; ptr = ptr ->next; } ptr1->next = NULL; free(ptr); printf("nDeleted Node from the last ...n"); }
  • 7. Random Delete node at Position struct node *ptr,*ptr1; int loc,i; printf("n Enter the location of the node after which you want to perform deletion n"); scanf("%d",&loc); ptr=head; for(i=0;i<loc;i++) { ptr1 = ptr; ptr = ptr->next; if(ptr == NULL) { printf("nCan't delete"); return; } } ptr1 ->next = ptr ->next; free(ptr); printf("nDeleted node %d ",loc+1);
  • 8. Find node in Linked List struct node *ptr; int item,i=0,flag; ptr = head; if(ptr == NULL) { printf("nEmpty Listn"); } else { printf("nEnter item which you want to search?n"); scanf("%d",&item); while (ptr!=NULL) { if(ptr->data == item) { printf("item found at location %d ",i+1); flag=0; } else { flag=1; } i++; ptr = ptr -> next; } if(flag==1) { printf("Item not foundn"); } }
  • 9. Display Linked List struct node *ptr; ptr = head; if(ptr == NULL) { printf("Nothing to print"); } else { printf("nprinting values . . . . .n"); while (ptr!=NULL) { printf("n%d",ptr->data); ptr = ptr -> next; } }
  • 10. DOUBLY LINKED LIST What is a doubly-linked list? A doubly linked list is another type of the linked list. It is called a doubly linked list because it contains two addresses while a singly linked list contains a single address. It is a list that has total three parts, one is a data part, and others two are the pointers, i.e., previous and next. The previous pointer holds the address of the previous node, and the next pointer holds the address of the next node. Therefore, we can say that list has two references, i.e., forward and backward reference to traverse in either direction. In c the structure of a node is describe as : struct node { struct node *prev; int data; struct node *next; }
  • 11.  Memory Representation of a doubly linked list is shown in the following image. Generally, doubly linked list consumes more space for every node and therefore, causes more expansive basic operations such as insertion and deletion. However, we can easily manipulate the elements of the list since the list maintains pointers in both the directions (forward and backward).  In the following image, the first element of the list that is i.e. 13 stored at address 1. The head pointer points to the starting address 1. Since this is the first element being added to the list therefore the prev of the list contains null. The next node of the list resides at address 4 therefore the first node contains 4 in its next pointer.  We can traverse the list in this way until we find any node containing null or -1 in its next part. MEMORY REPRESENTATION OF A DOUBLY LINKED LIST
  • 12. Insert at Begining struct node *ptr; int item; ptr = (struct node *)malloc(sizeof(struct node)); if(ptr == NULL) { printf("nOVERFLOW"); } else { printf("nEnter Item value"); scanf("%d",&item); if(head==NULL) { ptr->next = NULL; ptr->prev=NULL; ptr->data=item; head=ptr; } else { ptr->data=item; ptr->prev=NULL; ptr->next = head; head->prev=ptr; head=ptr; } printf("nNode insertedn"); } Insert at Last struct node *ptr,*temp; int item; ptr = (struct node *) malloc(sizeof(struct node)); if(ptr == NULL) { printf("nOVERFLOW"); } else { printf("nEnter value"); scanf("%d",&item); ptr->data=item; if(head == NULL) { ptr->next = NULL; ptr->prev = NULL; head = ptr; } else { temp = head; while(temp->next!=NULL) { temp = temp->next; } temp->next = ptr; ptr ->prev=temp; ptr->next = NULL; } } printf("nnode insertedn");
  • 13. Insert at Position struct node *ptr,*temp; int item,loc,i; ptr = (struct node *)malloc(sizeof(struct node)); if(ptr == NULL) { printf("n OVERFLOW"); } else { temp=head; printf("Enter the location"); scanf("%d",&loc); for(i=1;i<loc-1; i++) { temp = temp->next; if(temp == NULL) { printf("n There are less than %d elements", loc); return; } } printf("Enter value"); scanf("%d",&ptr->data); ptr -> prev = temp; ptr->next = temp->next; temp->next = ptr; temp->next->prev=ptr; printf("nnode insertedn"); } Deletion at Begining struct node *ptr; if(head == NULL) { printf("n UNDERFLOW"); } else if(head->next == NULL) { head = NULL; free(head); printf("n node deletedn"); } else { ptr = head; head = head -> next; head -> prev = NULL; free(ptr); printf("nnode deletedn"); }
  • 14. Deletion at last struct node *ptr; if(head == NULL) { printf("n UNDERFLOW"); } else if(head->next == NULL) { head = NULL; free(head); printf("nnode deletedn"); } else { ptr = head; if(ptr->next != NULL) { ptr = ptr -> next; } ptr -> prev -> next = NULL; free(ptr); printf("nnode deletedn"); } Deletion at Position struct node *ptr, *temp; int val; printf("n Enter the data after which the node is to be del eted : "); scanf("%d", &val); ptr = head; while(ptr -> data != val) ptr = ptr -> next; if(ptr -> next == NULL) { printf("nCan't deleten"); } else if(ptr -> next -> next == NULL) { ptr ->next = NULL; } else { temp = ptr -> next; ptr -> next = temp -> next; temp -> next -> prev = ptr; free(temp); printf("nnode deletedn"); }
  • 15. CIRCULAR LINKED LIST  In a circular Singly linked list, the last node of the list contains a pointer to the first node of the list. We can have circular singly linked list as well as circular doubly linked list.  We traverse a circular singly linked list until we reach the same node where we started. The circular singly liked list has no beginning and no ending. There is no null value present in the next part of any of the nodes.  The following image shows a circular singly linked list.
  • 16. Begin Insert struct node *ptr,*temp; int item; ptr = (struct node *)malloc(sizeof(struct node)); if(ptr == NULL) { printf("nOVERFLOW"); } else { printf("nEnter the node data?"); scanf("%d",&item); ptr -> data = item; if(head == NULL) { head = ptr; ptr -> next = head; } else { temp = head; while(temp->next != head) temp = temp->next; ptr->next = head; temp -> next = ptr; head = ptr; } printf("nnode insertedn"); } Last Insert struct node *ptr,*temp; int item; ptr = (struct node *)malloc(sizeof(struct node)); if(ptr == NULL) { printf("nOVERFLOWn"); } else { printf("nEnter Data?"); scanf("%d",&item); ptr->data = item; if(head == NULL) { head = ptr; ptr -> next = head; } else { temp = head; while(temp -> next != head) { temp = temp -> next; } temp -> next = ptr; ptr -> next = head; } printf("nnode insertedn"); }
  • 17. Begin Delete struct node *ptr; if(head == NULL) { printf("nUNDERFLOW"); } else if(head->next == head) { head = NULL; free(head); printf("nnode deletedn"); } else { ptr = head; while(ptr -> next != head) ptr = ptr -> next; ptr->next = head->next; free(head); head = ptr->next; printf("nnode deletedn"); } Last Delete struct node *ptr, *preptr; if(head==NULL) { printf("nUNDERFLOW"); } else if (head ->next == head) { head = NULL; free(head); printf("nnode deletedn"); } else { ptr = head; while(ptr ->next != head) { preptr=ptr; ptr = ptr->next; } preptr->next = ptr -> next; free(ptr); printf("nnode deletedn"); }
  • 18. Search node struct node *ptr; int item,i=0,flag=1; ptr = head; if(ptr == NULL) { printf("nEmpty Listn"); } else { printf("nEnter item which you want to search?n"); scanf("%d",&item); if(head ->data == item) { printf("item found at location %d",i+1); flag=0; } else { while (ptr->next != head) { if(ptr->data == item) { printf("item found at location %d ",i+1); flag=0; break; } else { flag=1; } i++; ptr = ptr -> next; } } if(flag != 0) { printf("Item not foundn"); } }
  • 19. Display linked list struct node *ptr; ptr=head; if(head == NULL) { printf("nnothing to print"); } else { printf("n printing values ... n"); while(ptr -> next != head) { printf("%dn", ptr -> data); ptr = ptr -> next; } printf("%dn", ptr -> data); }
  • 20. Dynamic memory allocation in C The concept of dynamic memory allocation in c language enables the C programmer to allocate memory at runtime. Dynamic memory allocation in c language is possible by 4 functions of stdlib.h header file. malloc() calloc() realloc() free() Before learning above functions, let's understand the difference between static memory allocation and dynamic memory allocation.
  • 21. static memory allocation dynamic memory allocation memory is allocated at compile time. memory is allocated at run time. memory can't be increased while executing program. memory can be increased while executing program. used in array. used in linked list. malloc() allocates single block of requested memory. calloc() allocates multiple block of requested memory. realloc() reallocates the memory occupied by malloc() or calloc() functions. free() frees the dynamically allocated memory.
  • 22. malloc ptr=(cast-type*)malloc(byte-size) Calloc ptr=(cast-t ype*)calloc(number, byte-size)  The calloc() function allocates multiple block of requested memory.  It initially initialize all bytes to zero.  It returns NULL if memory is not sufficient.