SlideShare a Scribd company logo
1 of 36
Program : CS(computer Science)
Semester : 3rd
Course : Data Structures & Algorithms
Presented By : Daniyal,Moazzam,Ayyan
Presented To : Prof. Asad Bilal
Topic : Linked List
Institute :
Introduction :
A linked list is a linear data structure, in which the
elements are not stored at contiguous memory locations.
The elements in a linked list are linked using pointers It is
implemented on the heap memory rather than the stack
memory as shown in the below image:
Types of Linked List
There are Three key types of linked lists:
Singly linked lists.
Doubly linked lists.
Circular linked lists.
Singly Linked List
 A Singly Linked List is a specialized case of a linked list. In a
singly linked list, each node links to only the next node in the
sequence i.e.;
Creation Of Node
 Node is a combination of two things One is Data & other is
Pointer that stores the address of next node.
Null
Head
5 Next
Code of Creating A Node in Singly Linked List
#include <iostream>
using namespace std;
class Node{
public:
int data;
Node* next;
Node (int d){
this-> data= d;
this-> next= Null;
}
};
int main(){
Node* node1 = new Node(5);
Node* head = node1;
}
Insertion in Singly Linked List
Insertion At Head:
• Create a Node
Temp Head
Null Null
Temp Head
Temp-> next= Head
Null
Head
Head = Temp
Null
1 5
1 5
1 5
next next
next next
next next
Code of Inserting Node at Head in Singly LL
void insertAtHead (Node* &head, int d) {
// new node create
Node* temp = new Node(d);
temp -> next = head;
head = temp;
}
int main(){
Node* node1 = new Node(5);
Node* head = node1;
insertAtHead (head,1);
}
Insertion at Tail:
• Create a Node
Temp Head/Tail
Null Null
Head/Tail Temp
Tail-> next = Temp
Null
Head / Temp/Tail
Tail = Temp
Null
2 next 1 next
1 next
Tail
2 next
1 next 2 next
Code of Inserting Node at Tail in Singly LL
void insertAtTail (Node* &head, Node* &tail, int d) {
// new node create
Node* temp = new Node(d);
tail -> next = temp;
tail = temp;
}
int main(){
Node* node1 = new Node(1);
Node* head = node1;
Node* tail = node1;
insertAtTail (head,tail,2);
}
Insertion at Middle
Code of Insertion at Middle
void insertAtPosition(Node* &tail, Node* & head, int position, int d) {
Node* temp = head;
int cnt = 1;
while(cnt < position-1) {
temp = temp->next;
cnt++;
}
//creating a node for d
Node* nodeToInsert = new Node(d);
nodeToInsert -> next = temp -> next;
temp -> next = nodeToInsert;
}
int main(){
insertAtPosition(tail, head, 2, 100);
}
Code for Traversing a Linked List
void print(Node* &head) {
if(head == NULL) {
cout << "List is empty "<< endl;
return ;
}
Node* temp = head;
while(temp != NULL ) {
cout << temp -> data << " ";
temp = temp -> next;
}
cout << endl;
}
Doubly Linked List
A Doubly Linked List (DLL) contains an extra pointer, typically
called the previous pointer, together with the next pointer and
data which are there in the singly linked list. i.e.;
Creation Of Node
 In Doubly linked list Node is a combination of three things One is
Data & other two are Pointer one stores the address of next
node and other stores the address of previous node.
Null Null
Head
5 Next
Previous
Code of Creating Node in Doubly Linked List
#include<iostream>
using namespace std;
class Node {
public:
int data;
Node* prev;
Node* next;
//constructor
Node(int d ) {
this-> data = d;
this->prev = NULL;
this->next = NULL;
}
};
Code for Insertion in Linked List
 Insertion at Head:
• Create a node
Temp Head
Null Null Null Null
Temp Temp->next = Head
Null Null Null
Temp
Head->Previous = Temp
Null Null
Head Temp
Head = Temp
Null Null
Previ
ous
1
Nex
t
Previ
ous
2
Nex
t
Previ
ous
1
Nex
t
Nex
t
1
1
Previ
ous
Previ
ous
Nex
t
Previ
ous
Previ
ous
Previ
ous
2
2
2
Nex
t
Nex
t
Nex
t
Head
Code for insertion at Head
void insertAtHead(Node* &tail, Node* &head, int d)
{
//empty list
if(head == NULL) {
Node* temp = new Node(d);
head = temp;
tail = temp;
}
else{
Node* temp = new Node(d);
temp -> next = head;
head -> prev = temp;
head = temp;
}
}
int main(){
insertAtHead(tail,head, 1);
}
Code for Insertion in Linked List
 Insertion at Tail:
• Create a node:
Head / Tail Temp
Null
Null Null Null
Head / Tail Tail->Next = Temp Temp
Null Head
Null
Head
Head->Previous = Temp
Null Null
Tail = Temp
Previ
ous
1
Nex
t
Previ
ous
2
Nex
t
Previ
ous
1
Nex
t
Nex
t
1
Previ
ous
Previ
ous
Previ
ous
2
2
Nex
t
Nex
t
temp/tail
Code for insertion at Tail
void insertAtTail(Node* &tail,Node* &head, int d)
{
if(tail == NULL) {
Node* temp = new Node(d);
tail = temp;
head = temp;
}
else{
Node* temp = new Node(d);
tail -> next = temp;
temp -> prev = tail;
tail = temp;
}
}
int main(){
insertAtTail(tail,head, 25);
}
Code of insertion at Middle
void insertAtPosition(Node* & tail, Node* &head, int position, int d)
Node* temp = head;
int cnt = 1;
while(cnt < position-1) {
temp = temp->next;
cnt++;
}
//creating a node for d
Node* nodeToInsert = new Node(d);
nodeToInsert ->next = temp -> next;
temp -> next -> prev = nodeToInsert;
temp -> next = nodeToInsert;
nodeToInsert -> prev = temp;
}
int main(){
insertAtPosition(tail, head, 7, 102);
}
Code for Traversing a Linked List
void print(Node* head)
{
Node* temp = head ;
while(temp != NULL) {
cout << temp -> data << " ";
temp = temp -> next;
}
cout << endl;
}
Circular Linked List
The circular linked list is a linked list where all nodes are
connected to form a circle. In a circular linked list, the first
node and the last node are connected to each other
which forms a circle. There is no NULL at the end.
Create a node
In Circular List Node is a combination of two things One is Data &
other is Pointer that stores the address of next node and the last
node points the first node.
1 Next
Code for creation a node in Circular Linked List
#include<iostream>
#include<map>
using namespace std;
class Node {
public:
int data;
Node* next;
//constructor
Node(int d) {
this->data = d;
this->next = NULL;
}
int main(){
Node* tail = NULL;
}
Code for Insertion a node in circular Linked List
void insertNode(Node* &tail, int element, int d) {
//empty list
if(tail == NULL) {
Node* newNode = new Node(d);
tail = newNode;
newNode -> next = newNode;
}
else{
//non-empty list
//assuming that the element is present in the list
Node* curr = tail;
while(curr->data != element) {
curr = curr -> next;
}
//element found -> curr is representing element wala node
Node* temp = new Node(d);
temp -> next = curr -> next;
curr -> next = temp;
}
}
Traversing a Node in Circular Linked List
void print(Node* tail) {
Node* temp = tail;
//empty list
if(tail == NULL) {
cout << "List is Empty "<< endl;
return ;
}
do
{
cout << tail -> data << " ";
tail = tail -> next;
}
while(tail != temp);
cout << endl;
}
Code for Deletion
of Nodes
Deletion of a Node in Singly Linked List
void deleteNode(int position, Node* & head) {
//deleting first or start node if(position == 1) {
Node* temp = head;
head = head -> next;
//memory free start node
temp -> next = NULL;
delete temp;
}
else
{
//deleting any middle node or last node
Node* curr = head;
Node* prev = NULL;
int cnt = 1;
while(cnt < position) {
prev = curr;
curr = curr -> next;
cnt++;
}
prev -> next = curr -> next;
curr -> next = NULL;
delete curr; }
}
Deletion of a Node in Doubly Linked List
void deleteNode(int position, Node* & head) {
//deleting first or start node
if(position == 1) {
Node* temp = head;
temp -> next -> prev = NULL;
head = temp ->next;
temp -> next = NULL;
delete temp;
}
else
{
//deleting any middle node or last node
Node* curr = head;
Node* prev = NULL;
int cnt = 1;
while(cnt < position) {
prev = curr;
curr = curr -> next;
cnt++;
}
curr -> prev = NULL;
prev -> next = curr -> next;
curr -> next = NULL;
delete curr; }
}
Deletion of node in Circular Linked List
void deleteNode(Node* &tail, int value) {
//empty list
if(tail == NULL) {
cout << " List is empty, please check again" << endl;
return;
}
else{
//assuming that "value" is present in the Linked List
Node* prev = tail;
Node* curr = prev -> next;
while(curr -> data != value) {
prev = curr;
curr = curr -> next;
}
prev -> next = curr -> next;
//1 Node Linked List
if(curr == prev) {
tail = NULL;
}
//>=2 Node linked list
else if(tail == curr ) {
tail = prev;
} curr -> next = NULL;
delete curr;
} }
So, We have our Questions for You People
?

More Related Content

Similar to DSA(1).pptx

Program to insert in a sorted list #includestdio.h#include.pdf
 Program to insert in a sorted list #includestdio.h#include.pdf Program to insert in a sorted list #includestdio.h#include.pdf
Program to insert in a sorted list #includestdio.h#include.pdfsudhirchourasia86
 
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
 
Lec-4_Linked-List (1).pdf
Lec-4_Linked-List (1).pdfLec-4_Linked-List (1).pdf
Lec-4_Linked-List (1).pdfKylaMaeGarcia1
 
In the class we extensively discussed a node class called IntNode in.pdf
In the class we extensively discussed a node class called IntNode in.pdfIn the class we extensively discussed a node class called IntNode in.pdf
In the class we extensively discussed a node class called IntNode in.pdfarjunstores123
 
C++ Please write the whole code that is needed for this assignment- wr.docx
C++ Please write the whole code that is needed for this assignment- wr.docxC++ Please write the whole code that is needed for this assignment- wr.docx
C++ Please write the whole code that is needed for this assignment- wr.docxBrianGHiNewmanv
 
How do you stop infinite loop Because I believe that it is making a.pdf
How do you stop infinite loop Because I believe that it is making a.pdfHow do you stop infinite loop Because I believe that it is making a.pdf
How do you stop infinite loop Because I believe that it is making a.pdffeelinggift
 
Doublylinklist
DoublylinklistDoublylinklist
Doublylinklistritu1806
 
#include iostream #includestdlib.h using namespace std;str.pdf
#include iostream #includestdlib.h using namespace std;str.pdf#include iostream #includestdlib.h using namespace std;str.pdf
#include iostream #includestdlib.h using namespace std;str.pdflakshmijewellery
 
C++Write a method Node Nodereverse() which reverses a list..pdf
C++Write a method Node Nodereverse() which reverses a list..pdfC++Write a method Node Nodereverse() which reverses a list..pdf
C++Write a method Node Nodereverse() which reverses a list..pdfarjunenterprises1978
 
C program to insert a node in doubly linked list
C program to insert a node in doubly linked listC program to insert a node in doubly linked list
C program to insert a node in doubly linked listSourav Gayen
 
1#include stdio.h#include stdlib.h#include assert.h .pdf
1#include stdio.h#include stdlib.h#include assert.h .pdf1#include stdio.h#include stdlib.h#include assert.h .pdf
1#include stdio.h#include stdlib.h#include assert.h .pdfsudhinjv
 
Unit 1 LINEAR DATA STRUCTURES
Unit 1  LINEAR DATA STRUCTURESUnit 1  LINEAR DATA STRUCTURES
Unit 1 LINEAR DATA STRUCTURESUsha Mahalingam
 

Similar to DSA(1).pptx (20)

Program to insert in a sorted list #includestdio.h#include.pdf
 Program to insert in a sorted list #includestdio.h#include.pdf Program to insert in a sorted list #includestdio.h#include.pdf
Program to insert in a sorted list #includestdio.h#include.pdf
 
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
 
17 linkedlist (1)
17 linkedlist (1)17 linkedlist (1)
17 linkedlist (1)
 
Lec-4_Linked-List (1).pdf
Lec-4_Linked-List (1).pdfLec-4_Linked-List (1).pdf
Lec-4_Linked-List (1).pdf
 
In the class we extensively discussed a node class called IntNode in.pdf
In the class we extensively discussed a node class called IntNode in.pdfIn the class we extensively discussed a node class called IntNode in.pdf
In the class we extensively discussed a node class called IntNode in.pdf
 
C++ Please write the whole code that is needed for this assignment- wr.docx
C++ Please write the whole code that is needed for this assignment- wr.docxC++ Please write the whole code that is needed for this assignment- wr.docx
C++ Please write the whole code that is needed for this assignment- wr.docx
 
Linked list
Linked listLinked list
Linked list
 
How do you stop infinite loop Because I believe that it is making a.pdf
How do you stop infinite loop Because I believe that it is making a.pdfHow do you stop infinite loop Because I believe that it is making a.pdf
How do you stop infinite loop Because I believe that it is making a.pdf
 
C Homework Help
C Homework HelpC Homework Help
C Homework Help
 
Linked list
Linked list Linked list
Linked list
 
Unit7 C
Unit7 CUnit7 C
Unit7 C
 
Doublylinklist
DoublylinklistDoublylinklist
Doublylinklist
 
#include iostream #includestdlib.h using namespace std;str.pdf
#include iostream #includestdlib.h using namespace std;str.pdf#include iostream #includestdlib.h using namespace std;str.pdf
#include iostream #includestdlib.h using namespace std;str.pdf
 
C++Write a method Node Nodereverse() which reverses a list..pdf
C++Write a method Node Nodereverse() which reverses a list..pdfC++Write a method Node Nodereverse() which reverses a list..pdf
C++Write a method Node Nodereverse() which reverses a list..pdf
 
C program to insert a node in doubly linked list
C program to insert a node in doubly linked listC program to insert a node in doubly linked list
C program to insert a node in doubly linked list
 
linked-list.ppt
linked-list.pptlinked-list.ppt
linked-list.ppt
 
1#include stdio.h#include stdlib.h#include assert.h .pdf
1#include stdio.h#include stdlib.h#include assert.h .pdf1#include stdio.h#include stdlib.h#include assert.h .pdf
1#include stdio.h#include stdlib.h#include assert.h .pdf
 
C Exam Help
C Exam Help C Exam Help
C Exam Help
 
Lab-2.4 101.pdf
Lab-2.4 101.pdfLab-2.4 101.pdf
Lab-2.4 101.pdf
 
Unit 1 LINEAR DATA STRUCTURES
Unit 1  LINEAR DATA STRUCTURESUnit 1  LINEAR DATA STRUCTURES
Unit 1 LINEAR DATA STRUCTURES
 

Recently uploaded

Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...
Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...
Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...amitlee9823
 
Midocean dropshipping via API with DroFx
Midocean dropshipping via API with DroFxMidocean dropshipping via API with DroFx
Midocean dropshipping via API with DroFxolyaivanovalion
 
Generative AI on Enterprise Cloud with NiFi and Milvus
Generative AI on Enterprise Cloud with NiFi and MilvusGenerative AI on Enterprise Cloud with NiFi and Milvus
Generative AI on Enterprise Cloud with NiFi and MilvusTimothy Spann
 
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Standamitlee9823
 
Invezz.com - Grow your wealth with trading signals
Invezz.com - Grow your wealth with trading signalsInvezz.com - Grow your wealth with trading signals
Invezz.com - Grow your wealth with trading signalsInvezz1
 
Halmar dropshipping via API with DroFx
Halmar  dropshipping  via API with DroFxHalmar  dropshipping  via API with DroFx
Halmar dropshipping via API with DroFxolyaivanovalion
 
5CL-ADBA,5cladba, Chinese supplier, safety is guaranteed
5CL-ADBA,5cladba, Chinese supplier, safety is guaranteed5CL-ADBA,5cladba, Chinese supplier, safety is guaranteed
5CL-ADBA,5cladba, Chinese supplier, safety is guaranteedamy56318795
 
Capstone Project on IBM Data Analytics Program
Capstone Project on IBM Data Analytics ProgramCapstone Project on IBM Data Analytics Program
Capstone Project on IBM Data Analytics ProgramMoniSankarHazra
 
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...amitlee9823
 
VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...
VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...
VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...SUHANI PANDEY
 
Call me @ 9892124323 Cheap Rate Call Girls in Vashi with Real Photo 100% Secure
Call me @ 9892124323  Cheap Rate Call Girls in Vashi with Real Photo 100% SecureCall me @ 9892124323  Cheap Rate Call Girls in Vashi with Real Photo 100% Secure
Call me @ 9892124323 Cheap Rate Call Girls in Vashi with Real Photo 100% SecurePooja Nehwal
 
Call Girls In Attibele ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Attibele ☎ 7737669865 🥵 Book Your One night StandCall Girls In Attibele ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Attibele ☎ 7737669865 🥵 Book Your One night Standamitlee9823
 
Mature dropshipping via API with DroFx.pptx
Mature dropshipping via API with DroFx.pptxMature dropshipping via API with DroFx.pptx
Mature dropshipping via API with DroFx.pptxolyaivanovalion
 
Call Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night StandCall Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night Standamitlee9823
 
Call Girls In Hsr Layout ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Hsr Layout ☎ 7737669865 🥵 Book Your One night StandCall Girls In Hsr Layout ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Hsr Layout ☎ 7737669865 🥵 Book Your One night Standamitlee9823
 
Week-01-2.ppt BBB human Computer interaction
Week-01-2.ppt BBB human Computer interactionWeek-01-2.ppt BBB human Computer interaction
Week-01-2.ppt BBB human Computer interactionfulawalesam
 
CebaBaby dropshipping via API with DroFX.pptx
CebaBaby dropshipping via API with DroFX.pptxCebaBaby dropshipping via API with DroFX.pptx
CebaBaby dropshipping via API with DroFX.pptxolyaivanovalion
 

Recently uploaded (20)

Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...
Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...
Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...
 
Anomaly detection and data imputation within time series
Anomaly detection and data imputation within time seriesAnomaly detection and data imputation within time series
Anomaly detection and data imputation within time series
 
Midocean dropshipping via API with DroFx
Midocean dropshipping via API with DroFxMidocean dropshipping via API with DroFx
Midocean dropshipping via API with DroFx
 
Generative AI on Enterprise Cloud with NiFi and Milvus
Generative AI on Enterprise Cloud with NiFi and MilvusGenerative AI on Enterprise Cloud with NiFi and Milvus
Generative AI on Enterprise Cloud with NiFi and Milvus
 
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Stand
 
Invezz.com - Grow your wealth with trading signals
Invezz.com - Grow your wealth with trading signalsInvezz.com - Grow your wealth with trading signals
Invezz.com - Grow your wealth with trading signals
 
Halmar dropshipping via API with DroFx
Halmar  dropshipping  via API with DroFxHalmar  dropshipping  via API with DroFx
Halmar dropshipping via API with DroFx
 
5CL-ADBA,5cladba, Chinese supplier, safety is guaranteed
5CL-ADBA,5cladba, Chinese supplier, safety is guaranteed5CL-ADBA,5cladba, Chinese supplier, safety is guaranteed
5CL-ADBA,5cladba, Chinese supplier, safety is guaranteed
 
Call Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts Service
Call Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts ServiceCall Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts Service
Call Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts Service
 
Capstone Project on IBM Data Analytics Program
Capstone Project on IBM Data Analytics ProgramCapstone Project on IBM Data Analytics Program
Capstone Project on IBM Data Analytics Program
 
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
 
VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...
VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...
VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...
 
Call me @ 9892124323 Cheap Rate Call Girls in Vashi with Real Photo 100% Secure
Call me @ 9892124323  Cheap Rate Call Girls in Vashi with Real Photo 100% SecureCall me @ 9892124323  Cheap Rate Call Girls in Vashi with Real Photo 100% Secure
Call me @ 9892124323 Cheap Rate Call Girls in Vashi with Real Photo 100% Secure
 
Call Girls In Attibele ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Attibele ☎ 7737669865 🥵 Book Your One night StandCall Girls In Attibele ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Attibele ☎ 7737669865 🥵 Book Your One night Stand
 
Mature dropshipping via API with DroFx.pptx
Mature dropshipping via API with DroFx.pptxMature dropshipping via API with DroFx.pptx
Mature dropshipping via API with DroFx.pptx
 
Call Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night StandCall Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night Stand
 
Call Girls In Hsr Layout ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Hsr Layout ☎ 7737669865 🥵 Book Your One night StandCall Girls In Hsr Layout ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Hsr Layout ☎ 7737669865 🥵 Book Your One night Stand
 
Week-01-2.ppt BBB human Computer interaction
Week-01-2.ppt BBB human Computer interactionWeek-01-2.ppt BBB human Computer interaction
Week-01-2.ppt BBB human Computer interaction
 
CebaBaby dropshipping via API with DroFX.pptx
CebaBaby dropshipping via API with DroFX.pptxCebaBaby dropshipping via API with DroFX.pptx
CebaBaby dropshipping via API with DroFX.pptx
 
(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7
(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7
(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7
 

DSA(1).pptx

  • 1.
  • 2. Program : CS(computer Science) Semester : 3rd Course : Data Structures & Algorithms Presented By : Daniyal,Moazzam,Ayyan Presented To : Prof. Asad Bilal Topic : Linked List
  • 3. Institute : Introduction : A linked list is a linear data structure, in which the elements are not stored at contiguous memory locations. The elements in a linked list are linked using pointers It is implemented on the heap memory rather than the stack memory as shown in the below image:
  • 4.
  • 5. Types of Linked List There are Three key types of linked lists: Singly linked lists. Doubly linked lists. Circular linked lists.
  • 6. Singly Linked List  A Singly Linked List is a specialized case of a linked list. In a singly linked list, each node links to only the next node in the sequence i.e.;
  • 7. Creation Of Node  Node is a combination of two things One is Data & other is Pointer that stores the address of next node. Null Head 5 Next
  • 8. Code of Creating A Node in Singly Linked List #include <iostream> using namespace std; class Node{ public: int data; Node* next; Node (int d){ this-> data= d; this-> next= Null; } }; int main(){ Node* node1 = new Node(5); Node* head = node1; }
  • 9. Insertion in Singly Linked List Insertion At Head: • Create a Node Temp Head Null Null Temp Head Temp-> next= Head Null Head Head = Temp Null 1 5 1 5 1 5 next next next next next next
  • 10. Code of Inserting Node at Head in Singly LL void insertAtHead (Node* &head, int d) { // new node create Node* temp = new Node(d); temp -> next = head; head = temp; } int main(){ Node* node1 = new Node(5); Node* head = node1; insertAtHead (head,1); }
  • 11. Insertion at Tail: • Create a Node Temp Head/Tail Null Null Head/Tail Temp Tail-> next = Temp Null Head / Temp/Tail Tail = Temp Null 2 next 1 next 1 next Tail 2 next 1 next 2 next
  • 12. Code of Inserting Node at Tail in Singly LL void insertAtTail (Node* &head, Node* &tail, int d) { // new node create Node* temp = new Node(d); tail -> next = temp; tail = temp; } int main(){ Node* node1 = new Node(1); Node* head = node1; Node* tail = node1; insertAtTail (head,tail,2); }
  • 14. Code of Insertion at Middle void insertAtPosition(Node* &tail, Node* & head, int position, int d) { Node* temp = head; int cnt = 1; while(cnt < position-1) { temp = temp->next; cnt++; } //creating a node for d Node* nodeToInsert = new Node(d); nodeToInsert -> next = temp -> next; temp -> next = nodeToInsert; } int main(){ insertAtPosition(tail, head, 2, 100); }
  • 15. Code for Traversing a Linked List void print(Node* &head) { if(head == NULL) { cout << "List is empty "<< endl; return ; } Node* temp = head; while(temp != NULL ) { cout << temp -> data << " "; temp = temp -> next; } cout << endl; }
  • 16. Doubly Linked List A Doubly Linked List (DLL) contains an extra pointer, typically called the previous pointer, together with the next pointer and data which are there in the singly linked list. i.e.;
  • 17. Creation Of Node  In Doubly linked list Node is a combination of three things One is Data & other two are Pointer one stores the address of next node and other stores the address of previous node. Null Null Head 5 Next Previous
  • 18. Code of Creating Node in Doubly Linked List #include<iostream> using namespace std; class Node { public: int data; Node* prev; Node* next; //constructor Node(int d ) { this-> data = d; this->prev = NULL; this->next = NULL; } };
  • 19. Code for Insertion in Linked List  Insertion at Head: • Create a node Temp Head Null Null Null Null Temp Temp->next = Head Null Null Null Temp Head->Previous = Temp Null Null Head Temp Head = Temp Null Null Previ ous 1 Nex t Previ ous 2 Nex t Previ ous 1 Nex t Nex t 1 1 Previ ous Previ ous Nex t Previ ous Previ ous Previ ous 2 2 2 Nex t Nex t Nex t Head
  • 20. Code for insertion at Head void insertAtHead(Node* &tail, Node* &head, int d) { //empty list if(head == NULL) { Node* temp = new Node(d); head = temp; tail = temp; } else{ Node* temp = new Node(d); temp -> next = head; head -> prev = temp; head = temp; } } int main(){ insertAtHead(tail,head, 1); }
  • 21. Code for Insertion in Linked List  Insertion at Tail: • Create a node: Head / Tail Temp Null Null Null Null Head / Tail Tail->Next = Temp Temp Null Head Null Head Head->Previous = Temp Null Null Tail = Temp Previ ous 1 Nex t Previ ous 2 Nex t Previ ous 1 Nex t Nex t 1 Previ ous Previ ous Previ ous 2 2 Nex t Nex t temp/tail
  • 22. Code for insertion at Tail void insertAtTail(Node* &tail,Node* &head, int d) { if(tail == NULL) { Node* temp = new Node(d); tail = temp; head = temp; } else{ Node* temp = new Node(d); tail -> next = temp; temp -> prev = tail; tail = temp; } } int main(){ insertAtTail(tail,head, 25); }
  • 23. Code of insertion at Middle void insertAtPosition(Node* & tail, Node* &head, int position, int d) Node* temp = head; int cnt = 1; while(cnt < position-1) { temp = temp->next; cnt++; } //creating a node for d Node* nodeToInsert = new Node(d); nodeToInsert ->next = temp -> next; temp -> next -> prev = nodeToInsert; temp -> next = nodeToInsert; nodeToInsert -> prev = temp; } int main(){ insertAtPosition(tail, head, 7, 102); }
  • 24. Code for Traversing a Linked List void print(Node* head) { Node* temp = head ; while(temp != NULL) { cout << temp -> data << " "; temp = temp -> next; } cout << endl; }
  • 25. Circular Linked List The circular linked list is a linked list where all nodes are connected to form a circle. In a circular linked list, the first node and the last node are connected to each other which forms a circle. There is no NULL at the end.
  • 26. Create a node In Circular List Node is a combination of two things One is Data & other is Pointer that stores the address of next node and the last node points the first node. 1 Next
  • 27. Code for creation a node in Circular Linked List #include<iostream> #include<map> using namespace std; class Node { public: int data; Node* next; //constructor Node(int d) { this->data = d; this->next = NULL; } int main(){ Node* tail = NULL; }
  • 28. Code for Insertion a node in circular Linked List void insertNode(Node* &tail, int element, int d) { //empty list if(tail == NULL) { Node* newNode = new Node(d); tail = newNode; newNode -> next = newNode; } else{ //non-empty list //assuming that the element is present in the list Node* curr = tail; while(curr->data != element) { curr = curr -> next; } //element found -> curr is representing element wala node Node* temp = new Node(d); temp -> next = curr -> next; curr -> next = temp; } }
  • 29. Traversing a Node in Circular Linked List void print(Node* tail) { Node* temp = tail; //empty list if(tail == NULL) { cout << "List is Empty "<< endl; return ; } do { cout << tail -> data << " "; tail = tail -> next; } while(tail != temp); cout << endl; }
  • 31. Deletion of a Node in Singly Linked List void deleteNode(int position, Node* & head) { //deleting first or start node if(position == 1) { Node* temp = head; head = head -> next; //memory free start node temp -> next = NULL; delete temp; } else { //deleting any middle node or last node Node* curr = head; Node* prev = NULL; int cnt = 1; while(cnt < position) { prev = curr; curr = curr -> next; cnt++; } prev -> next = curr -> next; curr -> next = NULL; delete curr; } }
  • 32. Deletion of a Node in Doubly Linked List void deleteNode(int position, Node* & head) { //deleting first or start node if(position == 1) { Node* temp = head; temp -> next -> prev = NULL; head = temp ->next; temp -> next = NULL; delete temp; } else { //deleting any middle node or last node Node* curr = head; Node* prev = NULL; int cnt = 1; while(cnt < position) { prev = curr; curr = curr -> next; cnt++; } curr -> prev = NULL; prev -> next = curr -> next; curr -> next = NULL; delete curr; } }
  • 33. Deletion of node in Circular Linked List void deleteNode(Node* &tail, int value) { //empty list if(tail == NULL) { cout << " List is empty, please check again" << endl; return; } else{ //assuming that "value" is present in the Linked List Node* prev = tail; Node* curr = prev -> next; while(curr -> data != value) { prev = curr; curr = curr -> next; } prev -> next = curr -> next; //1 Node Linked List if(curr == prev) { tail = NULL; } //>=2 Node linked list else if(tail == curr ) { tail = prev; } curr -> next = NULL; delete curr; } }
  • 34.
  • 35.
  • 36. So, We have our Questions for You People ?