SlideShare a Scribd company logo
1 of 5
Download to read offline
public static class LinkedDeque implements DequeADT{
private int size;
private Node first;
private Node last;
public LinkedDeque() {
}
// checking empty method or not
public boolean isEmpty() {
return first == null;
}
// checking size
public int size() {
return size;
}
// enqueing front
public void enqueueFront(T num) {
checkNull(num);
Node tempNode = new Node();
tempNode.num = num;
if (first != null) { // check root is not null
tempNode.next = first;
first.previous = tempNode;
}
first = tempNode;
if (last == null) last = first;
size++;
}
// removing front
public Item dequeueFront() {
CheckEmpty();
Node oldFirst = first;
first = first.next;
if (first == null)
last = null;
else
first.previous = null;
size--;
return oldFirst.item;
}
// inseeting element at end of list
public void enqueueBack(Item item) {
checkNull(item);
Node newLast = new Node();
newLast.item = item;
if (last != null) {
newLast.previous = last;
last.next = newLast;
}
last = newLast;
if (first == null) first = last;
size++;
}
// removing element from end of the list
public Item dequeueBack() {
CheckEmpty();
Node oldLast = last;
last = oldLast.previous;
if (last == null)
first = null;
else
last.next = null;
size--;
return oldLast.item;
}
private void CheckEmpty() {
if (first == null)
throw new NoSuchElementException();
}
private void checkNull(Item item) {
if (item == null)
throw new NullPointerException();
}
}
Solution
public static class LinkedDeque implements DequeADT{
private int size;
private Node first;
private Node last;
public LinkedDeque() {
}
// checking empty method or not
public boolean isEmpty() {
return first == null;
}
// checking size
public int size() {
return size;
}
// enqueing front
public void enqueueFront(T num) {
checkNull(num);
Node tempNode = new Node();
tempNode.num = num;
if (first != null) { // check root is not null
tempNode.next = first;
first.previous = tempNode;
}
first = tempNode;
if (last == null) last = first;
size++;
}
// removing front
public Item dequeueFront() {
CheckEmpty();
Node oldFirst = first;
first = first.next;
if (first == null)
last = null;
else
first.previous = null;
size--;
return oldFirst.item;
}
// inseeting element at end of list
public void enqueueBack(Item item) {
checkNull(item);
Node newLast = new Node();
newLast.item = item;
if (last != null) {
newLast.previous = last;
last.next = newLast;
}
last = newLast;
if (first == null) first = last;
size++;
}
// removing element from end of the list
public Item dequeueBack() {
CheckEmpty();
Node oldLast = last;
last = oldLast.previous;
if (last == null)
first = null;
else
last.next = null;
size--;
return oldLast.item;
}
private void CheckEmpty() {
if (first == null)
throw new NoSuchElementException();
}
private void checkNull(Item item) {
if (item == null)
throw new NullPointerException();
}
}

More Related Content

Similar to public static class LinkedDequeT implements DequeADTT{    priv.pdf

I need help in writing the test cases of the below methods i.pdf
I need help in writing the test cases of the below methods i.pdfI need help in writing the test cases of the below methods i.pdf
I need help in writing the test cases of the below methods i.pdf
adianantsolutions
 
#includeiostream#includecstdio#includecstdlib Node .pdf
#includeiostream#includecstdio#includecstdlib Node .pdf#includeiostream#includecstdio#includecstdlib Node .pdf
#includeiostream#includecstdio#includecstdlib Node .pdf
gulshan16175gs
 
PROBLEM STATEMENTIn this assignment, you will complete DoubleEnde.pdf
PROBLEM STATEMENTIn this assignment, you will complete DoubleEnde.pdfPROBLEM STATEMENTIn this assignment, you will complete DoubleEnde.pdf
PROBLEM STATEMENTIn this assignment, you will complete DoubleEnde.pdf
climatecontrolsv
 
I need help implementing a Stack with this java programming assignme.pdf
I need help implementing a Stack with this java programming assignme.pdfI need help implementing a Stack with this java programming assignme.pdf
I need help implementing a Stack with this java programming assignme.pdf
sauravmanwanicp
 
mainpublic class AssignmentThree {    public static void ma.pdf
mainpublic class AssignmentThree {    public static void ma.pdfmainpublic class AssignmentThree {    public static void ma.pdf
mainpublic class AssignmentThree {    public static void ma.pdf
fathimafancyjeweller
 
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdf
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdfHow do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdf
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdf
mail931892
 
import java-util-Iterator- import java-util-NoSuchElementException- im.pdf
import java-util-Iterator- import java-util-NoSuchElementException- im.pdfimport java-util-Iterator- import java-util-NoSuchElementException- im.pdf
import java-util-Iterator- import java-util-NoSuchElementException- im.pdf
Stewart29UReesa
 
Help explain the code with line comments public class CompletedLis.pdf
Help explain the code with line comments public class CompletedLis.pdfHelp explain the code with line comments public class CompletedLis.pdf
Help explain the code with line comments public class CompletedLis.pdf
almonardfans
 
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
malavshah9013
 
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
amrishinda
 
How do I fix it in javaLinkedList.java Defines a doubl.pdf
How do I fix it in javaLinkedList.java Defines a doubl.pdfHow do I fix it in javaLinkedList.java Defines a doubl.pdf
How do I fix it in javaLinkedList.java Defines a doubl.pdf
fmac5
 
How do I fix it in LinkedList.javaLinkedList.java Define.pdf
How do I fix it in LinkedList.javaLinkedList.java Define.pdfHow do I fix it in LinkedList.javaLinkedList.java Define.pdf
How do I fix it in LinkedList.javaLinkedList.java Define.pdf
mail931892
 
In the class we extensively discussed a generic singly linked list i.pdf
In the class we extensively discussed a generic singly linked list i.pdfIn the class we extensively discussed a generic singly linked list i.pdf
In the class we extensively discussed a generic singly linked list i.pdf
birajdar2
 
How do I fix it in LinkedList.javathis is what i didLabProgra.pdf
How do I fix it in LinkedList.javathis is what i didLabProgra.pdfHow do I fix it in LinkedList.javathis is what i didLabProgra.pdf
How do I fix it in LinkedList.javathis is what i didLabProgra.pdf
mail931892
 
Add functions push(int n- Deque &dq) and pop(Deque &dq)- Functions pus.docx
Add functions push(int n- Deque &dq) and pop(Deque &dq)- Functions pus.docxAdd functions push(int n- Deque &dq) and pop(Deque &dq)- Functions pus.docx
Add functions push(int n- Deque &dq) and pop(Deque &dq)- Functions pus.docx
WilliamZnlMarshallc
 
Please help write BinaryTree-java Thank you! Create a class BinaryTr.pdf
Please help write BinaryTree-java Thank you!   Create a class BinaryTr.pdfPlease help write BinaryTree-java Thank you!   Create a class BinaryTr.pdf
Please help write BinaryTree-java Thank you! Create a class BinaryTr.pdf
info750646
 

Similar to public static class LinkedDequeT implements DequeADTT{    priv.pdf (20)

I need help in writing the test cases of the below methods i.pdf
I need help in writing the test cases of the below methods i.pdfI need help in writing the test cases of the below methods i.pdf
I need help in writing the test cases of the below methods i.pdf
 
week-14x
week-14xweek-14x
week-14x
 
#includeiostream#includecstdio#includecstdlib Node .pdf
#includeiostream#includecstdio#includecstdlib Node .pdf#includeiostream#includecstdio#includecstdlib Node .pdf
#includeiostream#includecstdio#includecstdlib Node .pdf
 
PROBLEM STATEMENTIn this assignment, you will complete DoubleEnde.pdf
PROBLEM STATEMENTIn this assignment, you will complete DoubleEnde.pdfPROBLEM STATEMENTIn this assignment, you will complete DoubleEnde.pdf
PROBLEM STATEMENTIn this assignment, you will complete DoubleEnde.pdf
 
I need help implementing a Stack with this java programming assignme.pdf
I need help implementing a Stack with this java programming assignme.pdfI need help implementing a Stack with this java programming assignme.pdf
I need help implementing a Stack with this java programming assignme.pdf
 
mainpublic class AssignmentThree {    public static void ma.pdf
mainpublic class AssignmentThree {    public static void ma.pdfmainpublic class AssignmentThree {    public static void ma.pdf
mainpublic class AssignmentThree {    public static void ma.pdf
 
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdf
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdfHow do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdf
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdf
 
import java-util-Iterator- import java-util-NoSuchElementException- im.pdf
import java-util-Iterator- import java-util-NoSuchElementException- im.pdfimport java-util-Iterator- import java-util-NoSuchElementException- im.pdf
import java-util-Iterator- import java-util-NoSuchElementException- im.pdf
 
Help explain the code with line comments public class CompletedLis.pdf
Help explain the code with line comments public class CompletedLis.pdfHelp explain the code with line comments public class CompletedLis.pdf
Help explain the code with line comments public class CompletedLis.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
 
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
 
How do I fix it in javaLinkedList.java Defines a doubl.pdf
How do I fix it in javaLinkedList.java Defines a doubl.pdfHow do I fix it in javaLinkedList.java Defines a doubl.pdf
How do I fix it in javaLinkedList.java Defines a doubl.pdf
 
How do I fix it in LinkedList.javaLinkedList.java Define.pdf
How do I fix it in LinkedList.javaLinkedList.java Define.pdfHow do I fix it in LinkedList.javaLinkedList.java Define.pdf
How do I fix it in LinkedList.javaLinkedList.java Define.pdf
 
Linked Stack program.docx
Linked Stack program.docxLinked Stack program.docx
Linked Stack program.docx
 
In the class we extensively discussed a generic singly linked list i.pdf
In the class we extensively discussed a generic singly linked list i.pdfIn the class we extensively discussed a generic singly linked list i.pdf
In the class we extensively discussed a generic singly linked list i.pdf
 
How do I fix it in LinkedList.javathis is what i didLabProgra.pdf
How do I fix it in LinkedList.javathis is what i didLabProgra.pdfHow do I fix it in LinkedList.javathis is what i didLabProgra.pdf
How do I fix it in LinkedList.javathis is what i didLabProgra.pdf
 
Add functions push(int n- Deque &dq) and pop(Deque &dq)- Functions pus.docx
Add functions push(int n- Deque &dq) and pop(Deque &dq)- Functions pus.docxAdd functions push(int n- Deque &dq) and pop(Deque &dq)- Functions pus.docx
Add functions push(int n- Deque &dq) and pop(Deque &dq)- Functions pus.docx
 
Link list part 2
Link list part 2Link list part 2
Link list part 2
 
Please help write BinaryTree-java Thank you! Create a class BinaryTr.pdf
Please help write BinaryTree-java Thank you!   Create a class BinaryTr.pdfPlease help write BinaryTree-java Thank you!   Create a class BinaryTr.pdf
Please help write BinaryTree-java Thank you! Create a class BinaryTr.pdf
 
Java Concurrency Gotchas
Java Concurrency GotchasJava Concurrency Gotchas
Java Concurrency Gotchas
 

More from amaresh6333

4.1 (a) SoftwoodsThese generally come from the gymnosperm trees wh.pdf
4.1 (a) SoftwoodsThese generally come from the gymnosperm trees wh.pdf4.1 (a) SoftwoodsThese generally come from the gymnosperm trees wh.pdf
4.1 (a) SoftwoodsThese generally come from the gymnosperm trees wh.pdf
amaresh6333
 
10 leading causes of death in the United States In the recent sta.pdf
10 leading causes of death in the United States In the recent sta.pdf10 leading causes of death in the United States In the recent sta.pdf
10 leading causes of death in the United States In the recent sta.pdf
amaresh6333
 
C Program to shuffle a given Aay#include stdio.h #include .pdf
 C Program to shuffle a given Aay#include stdio.h #include .pdf C Program to shuffle a given Aay#include stdio.h #include .pdf
C Program to shuffle a given Aay#include stdio.h #include .pdf
amaresh6333
 
1.Router 1.It is a machine which aheads datagrams over the networks.pdf
1.Router 1.It is a machine which aheads datagrams over the networks.pdf1.Router 1.It is a machine which aheads datagrams over the networks.pdf
1.Router 1.It is a machine which aheads datagrams over the networks.pdf
amaresh6333
 
1) List currently running jobsANS) see currently runningcommand.pdf
1) List currently running jobsANS) see currently runningcommand.pdf1) List currently running jobsANS) see currently runningcommand.pdf
1) List currently running jobsANS) see currently runningcommand.pdf
amaresh6333
 
I would say very many elements exista as monoatom.pdf
                     I would say very many elements exista as monoatom.pdf                     I would say very many elements exista as monoatom.pdf
I would say very many elements exista as monoatom.pdf
amaresh6333
 
The important thing here is to understand the Standard Electrode Pot.pdf
The important thing here is to understand the Standard Electrode Pot.pdfThe important thing here is to understand the Standard Electrode Pot.pdf
The important thing here is to understand the Standard Electrode Pot.pdf
amaresh6333
 

More from amaresh6333 (20)

a) It is given E is the event of getting 2. We can observe that 2 is.pdf
a) It is given E is the event of getting 2. We can observe that 2 is.pdfa) It is given E is the event of getting 2. We can observe that 2 is.pdf
a) It is given E is the event of getting 2. We can observe that 2 is.pdf
 
4.1 (a) SoftwoodsThese generally come from the gymnosperm trees wh.pdf
4.1 (a) SoftwoodsThese generally come from the gymnosperm trees wh.pdf4.1 (a) SoftwoodsThese generally come from the gymnosperm trees wh.pdf
4.1 (a) SoftwoodsThese generally come from the gymnosperm trees wh.pdf
 
A special type of IP address is the limited broadcast address 255.25.pdf
A special type of IP address is the limited broadcast address 255.25.pdfA special type of IP address is the limited broadcast address 255.25.pdf
A special type of IP address is the limited broadcast address 255.25.pdf
 
10 leading causes of death in the United States In the recent sta.pdf
10 leading causes of death in the United States In the recent sta.pdf10 leading causes of death in the United States In the recent sta.pdf
10 leading causes of death in the United States In the recent sta.pdf
 
C Program to shuffle a given Aay#include stdio.h #include .pdf
 C Program to shuffle a given Aay#include stdio.h #include .pdf C Program to shuffle a given Aay#include stdio.h #include .pdf
C Program to shuffle a given Aay#include stdio.h #include .pdf
 
1.Router 1.It is a machine which aheads datagrams over the networks.pdf
1.Router 1.It is a machine which aheads datagrams over the networks.pdf1.Router 1.It is a machine which aheads datagrams over the networks.pdf
1.Router 1.It is a machine which aheads datagrams over the networks.pdf
 
1) List currently running jobsANS) see currently runningcommand.pdf
1) List currently running jobsANS) see currently runningcommand.pdf1) List currently running jobsANS) see currently runningcommand.pdf
1) List currently running jobsANS) see currently runningcommand.pdf
 
Step1 Total pressure = partial pressure of Hydrog.pdf
                     Step1 Total pressure = partial pressure of Hydrog.pdf                     Step1 Total pressure = partial pressure of Hydrog.pdf
Step1 Total pressure = partial pressure of Hydrog.pdf
 
I would say very many elements exista as monoatom.pdf
                     I would say very many elements exista as monoatom.pdf                     I would say very many elements exista as monoatom.pdf
I would say very many elements exista as monoatom.pdf
 
E is simply hexane...no polarity at all...nothing.pdf
                     E is simply hexane...no polarity at all...nothing.pdf                     E is simply hexane...no polarity at all...nothing.pdf
E is simply hexane...no polarity at all...nothing.pdf
 
Ferroxyl contains the chemical compound Potassium.pdf
                     Ferroxyl contains the chemical compound Potassium.pdf                     Ferroxyl contains the chemical compound Potassium.pdf
Ferroxyl contains the chemical compound Potassium.pdf
 
There are two different types of mechanisms. Ther.pdf
                     There are two different types of mechanisms. Ther.pdf                     There are two different types of mechanisms. Ther.pdf
There are two different types of mechanisms. Ther.pdf
 
What must be true about a set of data when its standard deviation is.pdf
What must be true about a set of data when its standard deviation is.pdfWhat must be true about a set of data when its standard deviation is.pdf
What must be true about a set of data when its standard deviation is.pdf
 
When one drives from sea level to trailhead in high Sierras, altitud.pdf
When one drives from sea level to trailhead in high Sierras, altitud.pdfWhen one drives from sea level to trailhead in high Sierras, altitud.pdf
When one drives from sea level to trailhead in high Sierras, altitud.pdf
 
the reaction as follows- 14N7 + 0n1 -- 4He2 + 1.pdf
                     the reaction as follows- 14N7 + 0n1 -- 4He2 + 1.pdf                     the reaction as follows- 14N7 + 0n1 -- 4He2 + 1.pdf
the reaction as follows- 14N7 + 0n1 -- 4He2 + 1.pdf
 
The important thing here is to understand the Standard Electrode Pot.pdf
The important thing here is to understand the Standard Electrode Pot.pdfThe important thing here is to understand the Standard Electrode Pot.pdf
The important thing here is to understand the Standard Electrode Pot.pdf
 
The pathway would be overactive.The GTPase activity of the alpha s.pdf
The pathway would be overactive.The GTPase activity of the alpha s.pdfThe pathway would be overactive.The GTPase activity of the alpha s.pdf
The pathway would be overactive.The GTPase activity of the alpha s.pdf
 
The metal ion is Pb2+.The white precipitate PbCl2 is insoluble in .pdf
The metal ion is Pb2+.The white precipitate PbCl2 is insoluble in .pdfThe metal ion is Pb2+.The white precipitate PbCl2 is insoluble in .pdf
The metal ion is Pb2+.The white precipitate PbCl2 is insoluble in .pdf
 
The electron carriers that feed into the ETC are NADH and FADH2.NA.pdf
The electron carriers that feed into the ETC are NADH and FADH2.NA.pdfThe electron carriers that feed into the ETC are NADH and FADH2.NA.pdf
The electron carriers that feed into the ETC are NADH and FADH2.NA.pdf
 
The developmental potential, or potency of a cell, describes the ran.pdf
The developmental potential, or potency of a cell, describes the ran.pdfThe developmental potential, or potency of a cell, describes the ran.pdf
The developmental potential, or potency of a cell, describes the ran.pdf
 

Recently uploaded

會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
中 央社
 
SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project research
CaitlinCummins3
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
中 央社
 
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaPersonalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
EADTU
 

Recently uploaded (20)

male presentation...pdf.................
male presentation...pdf.................male presentation...pdf.................
male presentation...pdf.................
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & Systems
 
How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17
 
Đề tieng anh thpt 2024 danh cho cac ban hoc sinh
Đề tieng anh thpt 2024 danh cho cac ban hoc sinhĐề tieng anh thpt 2024 danh cho cac ban hoc sinh
Đề tieng anh thpt 2024 danh cho cac ban hoc sinh
 
8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital Management8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital Management
 
diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....
 
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
 
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
 
SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project research
 
e-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopale-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopal
 
Mattingly "AI & Prompt Design: Named Entity Recognition"
Mattingly "AI & Prompt Design: Named Entity Recognition"Mattingly "AI & Prompt Design: Named Entity Recognition"
Mattingly "AI & Prompt Design: Named Entity Recognition"
 
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptxAnalyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
 
Observing-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxObserving-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptx
 
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaPersonalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
 
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjStl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
 
Trauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesTrauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical Principles
 
Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...
 
Graduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxGraduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptx
 

public static class LinkedDequeT implements DequeADTT{    priv.pdf

  • 1. public static class LinkedDeque implements DequeADT{ private int size; private Node first; private Node last; public LinkedDeque() { } // checking empty method or not public boolean isEmpty() { return first == null; } // checking size public int size() { return size; } // enqueing front public void enqueueFront(T num) { checkNull(num); Node tempNode = new Node(); tempNode.num = num; if (first != null) { // check root is not null tempNode.next = first; first.previous = tempNode; } first = tempNode; if (last == null) last = first; size++; } // removing front public Item dequeueFront() { CheckEmpty();
  • 2. Node oldFirst = first; first = first.next; if (first == null) last = null; else first.previous = null; size--; return oldFirst.item; } // inseeting element at end of list public void enqueueBack(Item item) { checkNull(item); Node newLast = new Node(); newLast.item = item; if (last != null) { newLast.previous = last; last.next = newLast; } last = newLast; if (first == null) first = last; size++; } // removing element from end of the list public Item dequeueBack() { CheckEmpty(); Node oldLast = last; last = oldLast.previous; if (last == null) first = null; else last.next = null; size--; return oldLast.item; }
  • 3. private void CheckEmpty() { if (first == null) throw new NoSuchElementException(); } private void checkNull(Item item) { if (item == null) throw new NullPointerException(); } } Solution public static class LinkedDeque implements DequeADT{ private int size; private Node first; private Node last; public LinkedDeque() { } // checking empty method or not public boolean isEmpty() { return first == null; } // checking size public int size() { return size; } // enqueing front public void enqueueFront(T num) { checkNull(num); Node tempNode = new Node(); tempNode.num = num; if (first != null) { // check root is not null
  • 4. tempNode.next = first; first.previous = tempNode; } first = tempNode; if (last == null) last = first; size++; } // removing front public Item dequeueFront() { CheckEmpty(); Node oldFirst = first; first = first.next; if (first == null) last = null; else first.previous = null; size--; return oldFirst.item; } // inseeting element at end of list public void enqueueBack(Item item) { checkNull(item); Node newLast = new Node(); newLast.item = item; if (last != null) { newLast.previous = last; last.next = newLast; } last = newLast; if (first == null) first = last; size++; } // removing element from end of the list
  • 5. public Item dequeueBack() { CheckEmpty(); Node oldLast = last; last = oldLast.previous; if (last == null) first = null; else last.next = null; size--; return oldLast.item; } private void CheckEmpty() { if (first == null) throw new NoSuchElementException(); } private void checkNull(Item item) { if (item == null) throw new NullPointerException(); } }