SlideShare a Scribd company logo
1 of 26
Linked Lists
Linked Stacks and Queues
front rear
top
0
0
Linked
Stack
Linked
Queue
Template of Queues
class Queue;
class Node {
friend class Queue;
private:
int info;
Node *link;
};
class Queue {
public:
Queue() {front = rear = NULL;};
void Add(int);
int Delete();
bool Empty();
private:
Node *front, *rear;
};
Queue Operations
front
×rear
Queue::Queue()
{
first = rear = NULL;
};
bool Empty()
{
if ( front==NULL)
return TRUE;
else
return FALSE;
}
Queue Operations
int Queue::Delete()
{
if (Empty())
{
cout <<“Queue underflow”;
exit(1);
}
Node *temp = front;
int x = temp->info;
front = temp->link;
if (front== NULL)
rear = NULL;
delete temp;
return x;
}
Queue Operations
front
rear
××
temp
642 8
void Queue::Add(int x)
{
Node *temp = new Node;
temp->info=x;
temp->link = NULL;
if (rear== NULL)
front = temp;
else
rear->link = temp;
rear = temp;
}
Queue Operations
front
rear
×
temp
642 8 ×10×
Various Linked Lists
 Adding an element in the beginning of
the list, or the end of the list
 Chains, circular lists
 Singly linked lists, doubly linked lists
 Etc.
Circular List
 Circular List: The tail of the list points
back to the head
 There is no NULL pointer to “end” the
list.
62 84
Circular List
 There is no first and last node in circular list so
we establish a first, last node by convention
First Node Last Node Last
 An external pointer is used to point to last
node.
62 84
Stacks as a Circular List
Let last be the pointer pointing to the last node in the stack
and first node be considered as top of the stack.
Implementation of Stack
class Stack;
class Node {
friend class Stack;
private:
int info;
Node *link;
};
class Stack {
public:
Stack() {last = NULL;};
void Push(int);
int Pop();
bool Empty();
private:
Node *last;
};
bool Stack::Empty()
{
if (last == NULL)
return TRUE;
else
return FALSE:
}
Stack Operations
void Stack::Push(int x)
{
Node * temp = new Node;
temp->info = x;
if (last == NULL)
last = temp;
else
temp->link = last->link;
last->link = temp;
}
PUSH
642
last
1
temp
int Stackint::Pop()
{
int x; Node *temp;
if (Empty()) {cout << “Empty Stack”; exit(1);}
temp = last->link;
x = temp->info;
if (temp == last)
last = NULL;
else
last->link = temp->link;
delete temp;
return x;
}
POP
642
last
1
temp
void Queue::Add(int x)
{
int x; Node *temp= new Node;
temp->info = x;
if (Empty())
last = temp;
else
temp->link = last->link;
last->link = temp;
last = temp;
}
Queue As Circular List
642
last
1
temp
8
void Queue::DelAfter(Node *p)
{
int x; Node *temp;
if (p==NULL || p==p->link)
{
cout << “void deletion”; return;
}
temp = p->link;
x = p->info;
p->link = temp->link;
delete temp;
}
DELAFTER()
642
last
1
temp
8
p
read n;
read(name);
while (name != END)
{
insert name on the circular list;
read(name);
}
while (there is more than one node on the list)
{
count through n-1 nodes on the list;
print the name in the nth node;
delete nth node
}
Print the name of the only node on the list
Josephus Problem
 List can not be traversed backward.
 A node can not be deleted from it,
given only a pointer to that node.
Solution is to use a Doubly Linked
List
Shortcomings of circular list
Doubly-Linked Lists
 Each node contains two pointers, one to its successor
and one to its predecessor.
 Doubly linked list can be linear or circular.
88NULL 42 109 NULL
head
left info right
88 42 109
Same basic functions operate on list
 Insertleft()
 Insertright()
 Delete()
 deleteleft()
 deleteright()
We have
left(right(p)) =p = right(left(p))
Doubly-Linked Lists
Doubly Link List
Let first be the pointer pointing to the first node in the
Doubly.
Implementation of Doubly
class Doubly;
class Node {
friend class Doubly;
private:
int info;
Node *left, *right;
};
class Doubly {
public:
Doubly() {first = NULL;};
-----------
private:
Node *first;
};
Delete
int Doubly::Delete(Node *p)
{
Node *q, *r; int x;
if (p==NULL)
{ cout << “void deletion”; return;}
x = p->info;
q = p->left;
r = p->right;
q->right = r;
r->left = q;
delete p;
DeleteLeft
void Doubly:: DelRight(Node *p)
{
Node *q, *temp;
int x;
r = p->right;
temp = r->right;
p->right = temp;
if (temp!=NULL)
temp->left = p;
cout << r->info;
delete r;
}
Insertright
void Doubly:: insertright(Node *p, int x)
{
Node *q, *r;
if (p==NULL)
{ cout << “void insertion”; return;}
q = new Node;
q->info = x;
r = p->right;
r->left = q;
q->right = r;
q->left = p;
p->right = q;
Insert on head side
void Doubly:: Insert(int x)
{
Node *q, *r;
r = first;
q = new Node;
q->info = x;
q->right = r;
q->left = NULL;
r->left = q;
first = q;
}
Deletion on head side
void Doubly:: Delete(int v)
{
Node *q, *r;
int x;
r = first;
q= r->right;
q->left = NULL;
r->right = NULL;
x = r->info;
first = q;
delete r;
}

More Related Content

What's hot

Lambda выражения и Java 8
Lambda выражения и Java 8Lambda выражения и Java 8
Lambda выражения и Java 8Alex Tumanoff
 
Single linked list
Single linked listSingle linked list
Single linked listSayantan Sur
 
Swift the implicit parts
Swift the implicit partsSwift the implicit parts
Swift the implicit partsMaxim Zaks
 
Circular linked list
Circular linked listCircular linked list
Circular linked listSayantan Sur
 
Introduction to functional programming using Ocaml
Introduction to functional programming using OcamlIntroduction to functional programming using Ocaml
Introduction to functional programming using Ocamlpramode_ce
 
Recursion concepts by Divya
Recursion concepts by DivyaRecursion concepts by Divya
Recursion concepts by DivyaDivya Kumari
 
Stack concepts by Divya
Stack concepts by DivyaStack concepts by Divya
Stack concepts by DivyaDivya Kumari
 
Queue Implementation Using Array & Linked List
Queue Implementation Using Array & Linked ListQueue Implementation Using Array & Linked List
Queue Implementation Using Array & Linked ListPTCL
 
Procedural Programming: It’s Back? It Never Went Away
Procedural Programming: It’s Back? It Never Went AwayProcedural Programming: It’s Back? It Never Went Away
Procedural Programming: It’s Back? It Never Went AwayKevlin Henney
 
3. Объекты, классы и пакеты в Java
3. Объекты, классы и пакеты в Java3. Объекты, классы и пакеты в Java
3. Объекты, классы и пакеты в JavaDEVTYPE
 

What's hot (19)

Lambda выражения и Java 8
Lambda выражения и Java 8Lambda выражения и Java 8
Lambda выражения и Java 8
 
Single linked list
Single linked listSingle linked list
Single linked list
 
Swift the implicit parts
Swift the implicit partsSwift the implicit parts
Swift the implicit parts
 
Circular linked list
Circular linked listCircular linked list
Circular linked list
 
Haskell 101
Haskell 101Haskell 101
Haskell 101
 
Introduction to functional programming using Ocaml
Introduction to functional programming using OcamlIntroduction to functional programming using Ocaml
Introduction to functional programming using Ocaml
 
Linked list
Linked list Linked list
Linked list
 
Recursion concepts by Divya
Recursion concepts by DivyaRecursion concepts by Divya
Recursion concepts by Divya
 
Stack concepts by Divya
Stack concepts by DivyaStack concepts by Divya
Stack concepts by Divya
 
Linked list
Linked listLinked list
Linked list
 
C sharp 8
C sharp 8C sharp 8
C sharp 8
 
Queue Implementation Using Array & Linked List
Queue Implementation Using Array & Linked ListQueue Implementation Using Array & Linked List
Queue Implementation Using Array & Linked List
 
A taste of Functional Programming
A taste of Functional ProgrammingA taste of Functional Programming
A taste of Functional Programming
 
Procedural Programming: It’s Back? It Never Went Away
Procedural Programming: It’s Back? It Never Went AwayProcedural Programming: It’s Back? It Never Went Away
Procedural Programming: It’s Back? It Never Went Away
 
3. Объекты, классы и пакеты в Java
3. Объекты, классы и пакеты в Java3. Объекты, классы и пакеты в Java
3. Объекты, классы и пакеты в Java
 
Linkedlist
LinkedlistLinkedlist
Linkedlist
 
C++ ARRAY WITH EXAMPLES
C++ ARRAY WITH EXAMPLESC++ ARRAY WITH EXAMPLES
C++ ARRAY WITH EXAMPLES
 
week-16x
week-16xweek-16x
week-16x
 
Linked list
Linked listLinked list
Linked list
 

Similar to Link list part 2

Help please, I have attached LinkedList.cpp and LinkedList.hPlease.pdf
Help please, I have attached LinkedList.cpp and LinkedList.hPlease.pdfHelp please, I have attached LinkedList.cpp and LinkedList.hPlease.pdf
Help please, I have attached LinkedList.cpp and LinkedList.hPlease.pdfarorastores
 
In C++Write a recursive function to determine whether or not a Lin.pdf
In C++Write a recursive function to determine whether or not a Lin.pdfIn C++Write a recursive function to determine whether or not a Lin.pdf
In C++Write a recursive function to determine whether or not a Lin.pdfflashfashioncasualwe
 
Here is the editable codeSolutionimport java.util.NoSuchEleme.pdf
Here is the editable codeSolutionimport java.util.NoSuchEleme.pdfHere is the editable codeSolutionimport java.util.NoSuchEleme.pdf
Here is the editable codeSolutionimport java.util.NoSuchEleme.pdfarrowmobile
 
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
 
hi i have to write a java program involving link lists. i have a pro.pdf
hi i have to write a java program involving link lists. i have a pro.pdfhi i have to write a java program involving link lists. i have a pro.pdf
hi i have to write a java program involving link lists. i have a pro.pdfarchgeetsenterprises
 
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
 
Data structures stacks
Data structures   stacksData structures   stacks
Data structures stacksmaamir farooq
 
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
 
JAVA A double-ended queue is a list that allows the addition and.pdf
JAVA A double-ended queue is a list that allows the addition and.pdfJAVA A double-ended queue is a list that allows the addition and.pdf
JAVA A double-ended queue is a list that allows the addition and.pdfamrishinda
 

Similar to Link list part 2 (20)

Help please, I have attached LinkedList.cpp and LinkedList.hPlease.pdf
Help please, I have attached LinkedList.cpp and LinkedList.hPlease.pdfHelp please, I have attached LinkedList.cpp and LinkedList.hPlease.pdf
Help please, I have attached LinkedList.cpp and LinkedList.hPlease.pdf
 
Stack queue
Stack queueStack queue
Stack queue
 
Stack queue
Stack queueStack queue
Stack queue
 
Stack queue
Stack queueStack queue
Stack queue
 
Stack queue
Stack queueStack queue
Stack queue
 
Stack queue
Stack queueStack queue
Stack queue
 
Stack queue
Stack queueStack queue
Stack queue
 
In C++Write a recursive function to determine whether or not a Lin.pdf
In C++Write a recursive function to determine whether or not a Lin.pdfIn C++Write a recursive function to determine whether or not a Lin.pdf
In C++Write a recursive function to determine whether or not a Lin.pdf
 
Unit - 2.pdf
Unit - 2.pdfUnit - 2.pdf
Unit - 2.pdf
 
Stack and queue
Stack and queueStack and queue
Stack and queue
 
Linked Stack program.docx
Linked Stack program.docxLinked Stack program.docx
Linked Stack program.docx
 
Here is the editable codeSolutionimport java.util.NoSuchEleme.pdf
Here is the editable codeSolutionimport java.util.NoSuchEleme.pdfHere is the editable codeSolutionimport java.util.NoSuchEleme.pdf
Here is the editable codeSolutionimport java.util.NoSuchEleme.pdf
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
 
Ds 2 cycle
Ds 2 cycleDs 2 cycle
Ds 2 cycle
 
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
 
hi i have to write a java program involving link lists. i have a pro.pdf
hi i have to write a java program involving link lists. i have a pro.pdfhi i have to write a java program involving link lists. i have a pro.pdf
hi i have to write a java program involving link lists. i have a pro.pdf
 
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
 
Data structures stacks
Data structures   stacksData structures   stacks
Data structures stacks
 
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
 
JAVA A double-ended queue is a list that allows the addition and.pdf
JAVA A double-ended queue is a list that allows the addition and.pdfJAVA A double-ended queue is a list that allows the addition and.pdf
JAVA A double-ended queue is a list that allows the addition and.pdf
 

More from Anaya Zafar

data structures and its importance
 data structures and its importance  data structures and its importance
data structures and its importance Anaya Zafar
 
Lec 2 algorithms efficiency complexity
Lec 2 algorithms efficiency  complexityLec 2 algorithms efficiency  complexity
Lec 2 algorithms efficiency complexityAnaya Zafar
 
Link list part 1
Link list part 1Link list part 1
Link list part 1Anaya Zafar
 
Dijkstra's algorithm
Dijkstra's algorithm Dijkstra's algorithm
Dijkstra's algorithm Anaya Zafar
 
The miracle-morning
The miracle-morningThe miracle-morning
The miracle-morningAnaya Zafar
 
How to write a meeting agenda?
How to write a  meeting agenda?How to write a  meeting agenda?
How to write a meeting agenda?Anaya Zafar
 
How we achieve our goals
How we achieve our goalsHow we achieve our goals
How we achieve our goalsAnaya Zafar
 
Ch 22 question solution of fundamental of physics 8th edition by HRW
Ch 22  question solution of fundamental of physics 8th edition by HRWCh 22  question solution of fundamental of physics 8th edition by HRW
Ch 22 question solution of fundamental of physics 8th edition by HRWAnaya Zafar
 
Ch 21 question solution of fundamental of physics 8th edition by HRW
Ch 21 question solution of fundamental of physics 8th edition by HRWCh 21 question solution of fundamental of physics 8th edition by HRW
Ch 21 question solution of fundamental of physics 8th edition by HRWAnaya Zafar
 
Definition of capacitance
Definition of capacitanceDefinition of capacitance
Definition of capacitanceAnaya Zafar
 
Chapter 24-capacitance
Chapter 24-capacitanceChapter 24-capacitance
Chapter 24-capacitanceAnaya Zafar
 
Capacitance and dielectrics
Capacitance and dielectrics Capacitance and dielectrics
Capacitance and dielectrics Anaya Zafar
 
20 electric current resistance ohms law
20 electric current resistance ohms law20 electric current resistance ohms law
20 electric current resistance ohms lawAnaya Zafar
 
Voltage, current, resistance, and ohm's law
Voltage, current, resistance, and ohm's lawVoltage, current, resistance, and ohm's law
Voltage, current, resistance, and ohm's lawAnaya Zafar
 
Role of women in development
Role of women in developmentRole of women in development
Role of women in developmentAnaya Zafar
 
Application of Gauss's law
Application of  Gauss's lawApplication of  Gauss's law
Application of Gauss's lawAnaya Zafar
 
Why we need Gaussian surface in Gauss's law
Why we need Gaussian surface in Gauss's lawWhy we need Gaussian surface in Gauss's law
Why we need Gaussian surface in Gauss's lawAnaya Zafar
 

More from Anaya Zafar (20)

data structures and its importance
 data structures and its importance  data structures and its importance
data structures and its importance
 
heap sort
 heap sort heap sort
heap sort
 
Lec 2 algorithms efficiency complexity
Lec 2 algorithms efficiency  complexityLec 2 algorithms efficiency  complexity
Lec 2 algorithms efficiency complexity
 
Link list part 1
Link list part 1Link list part 1
Link list part 1
 
Dijkstra's algorithm
Dijkstra's algorithm Dijkstra's algorithm
Dijkstra's algorithm
 
The miracle-morning
The miracle-morningThe miracle-morning
The miracle-morning
 
How to write a meeting agenda?
How to write a  meeting agenda?How to write a  meeting agenda?
How to write a meeting agenda?
 
How we achieve our goals
How we achieve our goalsHow we achieve our goals
How we achieve our goals
 
Fiber optics
Fiber opticsFiber optics
Fiber optics
 
3 d technology
3 d technology3 d technology
3 d technology
 
Ch 22 question solution of fundamental of physics 8th edition by HRW
Ch 22  question solution of fundamental of physics 8th edition by HRWCh 22  question solution of fundamental of physics 8th edition by HRW
Ch 22 question solution of fundamental of physics 8th edition by HRW
 
Ch 21 question solution of fundamental of physics 8th edition by HRW
Ch 21 question solution of fundamental of physics 8th edition by HRWCh 21 question solution of fundamental of physics 8th edition by HRW
Ch 21 question solution of fundamental of physics 8th edition by HRW
 
Definition of capacitance
Definition of capacitanceDefinition of capacitance
Definition of capacitance
 
Chapter 24-capacitance
Chapter 24-capacitanceChapter 24-capacitance
Chapter 24-capacitance
 
Capacitance and dielectrics
Capacitance and dielectrics Capacitance and dielectrics
Capacitance and dielectrics
 
20 electric current resistance ohms law
20 electric current resistance ohms law20 electric current resistance ohms law
20 electric current resistance ohms law
 
Voltage, current, resistance, and ohm's law
Voltage, current, resistance, and ohm's lawVoltage, current, resistance, and ohm's law
Voltage, current, resistance, and ohm's law
 
Role of women in development
Role of women in developmentRole of women in development
Role of women in development
 
Application of Gauss's law
Application of  Gauss's lawApplication of  Gauss's law
Application of Gauss's law
 
Why we need Gaussian surface in Gauss's law
Why we need Gaussian surface in Gauss's lawWhy we need Gaussian surface in Gauss's law
Why we need Gaussian surface in Gauss's law
 

Recently uploaded

What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfphamnguyenenglishnb
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxDr.Ibrahim Hassaan
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomnelietumpap1
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfSpandanaRallapalli
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
ROOT CAUSE ANALYSIS PowerPoint Presentation
ROOT CAUSE ANALYSIS PowerPoint PresentationROOT CAUSE ANALYSIS PowerPoint Presentation
ROOT CAUSE ANALYSIS PowerPoint PresentationAadityaSharma884161
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...Nguyen Thanh Tu Collection
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfMr Bounab Samir
 
Quarter 4 Peace-education.pptx Catch Up Friday
Quarter 4 Peace-education.pptx Catch Up FridayQuarter 4 Peace-education.pptx Catch Up Friday
Quarter 4 Peace-education.pptx Catch Up FridayMakMakNepo
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 

Recently uploaded (20)

Rapple "Scholarly Communications and the Sustainable Development Goals"
Rapple "Scholarly Communications and the Sustainable Development Goals"Rapple "Scholarly Communications and the Sustainable Development Goals"
Rapple "Scholarly Communications and the Sustainable Development Goals"
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptx
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choom
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdf
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
ROOT CAUSE ANALYSIS PowerPoint Presentation
ROOT CAUSE ANALYSIS PowerPoint PresentationROOT CAUSE ANALYSIS PowerPoint Presentation
ROOT CAUSE ANALYSIS PowerPoint Presentation
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Quarter 4 Peace-education.pptx Catch Up Friday
Quarter 4 Peace-education.pptx Catch Up FridayQuarter 4 Peace-education.pptx Catch Up Friday
Quarter 4 Peace-education.pptx Catch Up Friday
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 

Link list part 2

  • 2. Linked Stacks and Queues front rear top 0 0 Linked Stack Linked Queue
  • 3. Template of Queues class Queue; class Node { friend class Queue; private: int info; Node *link; }; class Queue { public: Queue() {front = rear = NULL;}; void Add(int); int Delete(); bool Empty(); private: Node *front, *rear; };
  • 5. bool Empty() { if ( front==NULL) return TRUE; else return FALSE; } Queue Operations
  • 6. int Queue::Delete() { if (Empty()) { cout <<“Queue underflow”; exit(1); } Node *temp = front; int x = temp->info; front = temp->link; if (front== NULL) rear = NULL; delete temp; return x; } Queue Operations front rear ×× temp 642 8
  • 7. void Queue::Add(int x) { Node *temp = new Node; temp->info=x; temp->link = NULL; if (rear== NULL) front = temp; else rear->link = temp; rear = temp; } Queue Operations front rear × temp 642 8 ×10×
  • 8. Various Linked Lists  Adding an element in the beginning of the list, or the end of the list  Chains, circular lists  Singly linked lists, doubly linked lists  Etc.
  • 9. Circular List  Circular List: The tail of the list points back to the head  There is no NULL pointer to “end” the list. 62 84
  • 10. Circular List  There is no first and last node in circular list so we establish a first, last node by convention First Node Last Node Last  An external pointer is used to point to last node. 62 84
  • 11. Stacks as a Circular List Let last be the pointer pointing to the last node in the stack and first node be considered as top of the stack. Implementation of Stack class Stack; class Node { friend class Stack; private: int info; Node *link; }; class Stack { public: Stack() {last = NULL;}; void Push(int); int Pop(); bool Empty(); private: Node *last; };
  • 12. bool Stack::Empty() { if (last == NULL) return TRUE; else return FALSE: } Stack Operations
  • 13. void Stack::Push(int x) { Node * temp = new Node; temp->info = x; if (last == NULL) last = temp; else temp->link = last->link; last->link = temp; } PUSH 642 last 1 temp
  • 14. int Stackint::Pop() { int x; Node *temp; if (Empty()) {cout << “Empty Stack”; exit(1);} temp = last->link; x = temp->info; if (temp == last) last = NULL; else last->link = temp->link; delete temp; return x; } POP 642 last 1 temp
  • 15. void Queue::Add(int x) { int x; Node *temp= new Node; temp->info = x; if (Empty()) last = temp; else temp->link = last->link; last->link = temp; last = temp; } Queue As Circular List 642 last 1 temp 8
  • 16. void Queue::DelAfter(Node *p) { int x; Node *temp; if (p==NULL || p==p->link) { cout << “void deletion”; return; } temp = p->link; x = p->info; p->link = temp->link; delete temp; } DELAFTER() 642 last 1 temp 8 p
  • 17. read n; read(name); while (name != END) { insert name on the circular list; read(name); } while (there is more than one node on the list) { count through n-1 nodes on the list; print the name in the nth node; delete nth node } Print the name of the only node on the list Josephus Problem
  • 18.  List can not be traversed backward.  A node can not be deleted from it, given only a pointer to that node. Solution is to use a Doubly Linked List Shortcomings of circular list
  • 19. Doubly-Linked Lists  Each node contains two pointers, one to its successor and one to its predecessor.  Doubly linked list can be linear or circular. 88NULL 42 109 NULL head left info right 88 42 109
  • 20. Same basic functions operate on list  Insertleft()  Insertright()  Delete()  deleteleft()  deleteright() We have left(right(p)) =p = right(left(p)) Doubly-Linked Lists
  • 21. Doubly Link List Let first be the pointer pointing to the first node in the Doubly. Implementation of Doubly class Doubly; class Node { friend class Doubly; private: int info; Node *left, *right; }; class Doubly { public: Doubly() {first = NULL;}; ----------- private: Node *first; };
  • 22. Delete int Doubly::Delete(Node *p) { Node *q, *r; int x; if (p==NULL) { cout << “void deletion”; return;} x = p->info; q = p->left; r = p->right; q->right = r; r->left = q; delete p;
  • 23. DeleteLeft void Doubly:: DelRight(Node *p) { Node *q, *temp; int x; r = p->right; temp = r->right; p->right = temp; if (temp!=NULL) temp->left = p; cout << r->info; delete r; }
  • 24. Insertright void Doubly:: insertright(Node *p, int x) { Node *q, *r; if (p==NULL) { cout << “void insertion”; return;} q = new Node; q->info = x; r = p->right; r->left = q; q->right = r; q->left = p; p->right = q;
  • 25. Insert on head side void Doubly:: Insert(int x) { Node *q, *r; r = first; q = new Node; q->info = x; q->right = r; q->left = NULL; r->left = q; first = q; }
  • 26. Deletion on head side void Doubly:: Delete(int v) { Node *q, *r; int x; r = first; q= r->right; q->left = NULL; r->right = NULL; x = r->info; first = q; delete r; }