SlideShare a Scribd company logo
1 of 4
Download to read offline
package ex2;
public class Exercise2<E> {
private static class Node<E> {
private E element;
private Node<E> prev;
private Node<E> next;
public Node(E e, Node<E> p, Node<E> n) {
element = e;
prev = p;
next = n;
}
public E getElement() { return element; }
public Node<E> getPrev() { return prev; }
public Node<E> getNext() { return next; }
public void setPrev(Node<E> p) { prev = p; }
public void setNext(Node<E> n) { next = n; }
}
private Node<E> header;
private Node<E> trailer;
private int size = 0;
public Exercise2() {
header = new Node<>(null, null, null);
trailer = new Node<>(null, header, null);
header.setNext(trailer);
}
public int size() { return size; }
public boolean isEmpty() { return size == 0; }
public E first() {
if (isEmpty()) return null;
return header.getNext().getElement();
}
public E last() {
if (isEmpty()) return null;
return trailer.getPrev().getElement();
}
public void addFirst(E e) {
addBetween(e, header, header.getNext());
}
public void addLast(E e) {
addBetween(e, trailer.getPrev(), trailer);
}
public E removeFirst() {
if (isEmpty()) return null;
return remove(header.getNext());
}
public E removeLast() {
if (isEmpty()) return null;
return remove(trailer.getPrev());
}
private void addBetween(E e, Node<E> predecessor, Node<E> successor) {
if (predecessor == header && successor == trailer) {
// skip creation of new node for header/trailer
header.setNext(new Node<>(e, header, trailer));
trailer.setPrev(header.getNext());
} else {
Node<E> newest = new Node<>(e, predecessor, successor);
predecessor.setNext(newest);
successor.setPrev(newest);
}
size++;
}
private E remove(Node<E> node) {
Node<E> predecessor = node.getPrev();
Node<E> successor = node.getNext();
predecessor.setNext(successor);
successor.setPrev(predecessor);
size--;
return node.getElement();
}
public String toString() {
StringBuilder sb = new StringBuilder("(");
Node<E> walk = header;
while (walk != null) {
sb.append(walk.getElement());
walk = walk.getNext();
if (walk != null) {
sb.append(", ");
}
}
sb.append(")");
return sb.toString();
}
public void reverseList() {
Node<E> current = header;
header = trailer.getPrev();
trailer = current.getNext();
while (current != null) {
Node<E> temp = current.getNext();
current.setNext(current.getPrev());
current.setPrev(temp);
current = temp;
}
}
public static void main(String[] args)
{
Exercise2<String> list = new Exercise2<String>();
list.addFirst("MSP");
list.addLast("ATL");
list.addLast("BOS");
list.addFirst("LAX");
System.out.println(list);
list.reverseList();
System.out.println(list);
}
}
Here's my code, the output should reverse the list, but I'm keep getting errors, anyone mind to
help me to get a proper output?
package ex2- public class Exercise2-E- {        private static class N.pdf

More Related Content

Similar to package ex2- public class Exercise2-E- { private static class N.pdf

Point.javapublic class Point { ย ย  int x,y; ย ย  double m,n; .pdf
Point.javapublic class Point { ย ย  int x,y; ย ย  double m,n; .pdfPoint.javapublic class Point { ย ย  int x,y; ย ย  double m,n; .pdf
Point.javapublic class Point { ย ย  int x,y; ย ย  double m,n; .pdf
anokhilalmobile
ย 
package com.java2novice.ds.linkedlist;import java.util.NoSuchEleme.pdf
package com.java2novice.ds.linkedlist;import java.util.NoSuchEleme.pdfpackage com.java2novice.ds.linkedlist;import java.util.NoSuchEleme.pdf
package com.java2novice.ds.linkedlist;import java.util.NoSuchEleme.pdf
aptind
ย 
Given below is the completed implementation of MyLinkedList class. O.pdf
Given below is the completed implementation of MyLinkedList class. O.pdfGiven below is the completed implementation of MyLinkedList class. O.pdf
Given below is the completed implementation of MyLinkedList class. O.pdf
info430661
ย 
Works Applications Test - Chinmay Chauhan
Works Applications Test - Chinmay ChauhanWorks Applications Test - Chinmay Chauhan
Works Applications Test - Chinmay Chauhan
Chinmay Chauhan
ย 
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
ย 
public class MyLinkedListltE extends ComparableltEgtg.pdf
public class MyLinkedListltE extends ComparableltEgtg.pdfpublic class MyLinkedListltE extends ComparableltEgtg.pdf
public class MyLinkedListltE extends ComparableltEgtg.pdf
accostinternational
ย 
Help I keep getting the same error when running a code. Below is the.pdf
Help I keep getting the same error when running a code. Below is the.pdfHelp I keep getting the same error when running a code. Below is the.pdf
Help I keep getting the same error when running a code. Below is the.pdf
mail931892
ย 
Hi,I have modified the Point.java file as per your requirement.P.pdf
Hi,I have modified the Point.java file as per your requirement.P.pdfHi,I have modified the Point.java file as per your requirement.P.pdf
Hi,I have modified the Point.java file as per your requirement.P.pdf
anokhijew
ย 
Solutionclass IntNode { int data; public IntNode next,head;.pdf
Solutionclass IntNode { int data; public IntNode next,head;.pdfSolutionclass IntNode { int data; public IntNode next,head;.pdf
Solutionclass IntNode { int data; public IntNode next,head;.pdf
rakeshankur
ย 
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
ย 
output and explain There is Mylist There is MyArrayList pa.pdf
output and explain There is Mylist There is MyArrayList pa.pdfoutput and explain There is Mylist There is MyArrayList pa.pdf
output and explain There is Mylist There is MyArrayList pa.pdf
access2future1
ย 
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
ย 
Complete the class ArraySet1java which implements the SetA.pdf
Complete the class ArraySet1java which implements the SetA.pdfComplete the class ArraySet1java which implements the SetA.pdf
Complete the class ArraySet1java which implements the SetA.pdf
abbecindia
ย 
Please finish everything marked TODO BinaryNode-java public class Bi.docx
Please finish everything marked TODO   BinaryNode-java public class Bi.docxPlease finish everything marked TODO   BinaryNode-java public class Bi.docx
Please finish everything marked TODO BinaryNode-java public class Bi.docx
JakeT2gGrayp
ย 
Java ะฒะตัะฝะฐ 2013 ะปะตะบั†ะธั 2
Java ะฒะตัะฝะฐ 2013 ะปะตะบั†ะธั 2Java ะฒะตัะฝะฐ 2013 ะปะตะบั†ะธั 2
Java ะฒะตัะฝะฐ 2013 ะปะตะบั†ะธั 2
Technopark
ย 
To complete the task, you need to fill in the missing code. Iโ€™ve inc.pdf
To complete the task, you need to fill in the missing code. Iโ€™ve inc.pdfTo complete the task, you need to fill in the missing code. Iโ€™ve inc.pdf
To complete the task, you need to fill in the missing code. Iโ€™ve inc.pdf
ezycolours78
ย 
STAGE 2 The Methods 65 points Implement all the methods t.pdf
STAGE 2 The Methods 65 points Implement all the methods t.pdfSTAGE 2 The Methods 65 points Implement all the methods t.pdf
STAGE 2 The Methods 65 points Implement all the methods t.pdf
babitasingh698417
ย 
This is problem is same problem which i submitted on 22017, I just.pdf
This is problem is same problem which i submitted on 22017, I just.pdfThis is problem is same problem which i submitted on 22017, I just.pdf
This is problem is same problem which i submitted on 22017, I just.pdf
fcaindore
ย 
code#includeiostream using namespace std; class Point {.pdf
code#includeiostream using namespace std; class Point {.pdfcode#includeiostream using namespace std; class Point {.pdf
code#includeiostream using namespace std; class Point {.pdf
ARYAN20071
ย 

Similar to package ex2- public class Exercise2-E- { private static class N.pdf (20)

Point.javapublic class Point { ย ย  int x,y; ย ย  double m,n; .pdf
Point.javapublic class Point { ย ย  int x,y; ย ย  double m,n; .pdfPoint.javapublic class Point { ย ย  int x,y; ย ย  double m,n; .pdf
Point.javapublic class Point { ย ย  int x,y; ย ย  double m,n; .pdf
ย 
6. Generics. Collections. Streams
6. Generics. Collections. Streams6. Generics. Collections. Streams
6. Generics. Collections. Streams
ย 
package com.java2novice.ds.linkedlist;import java.util.NoSuchEleme.pdf
package com.java2novice.ds.linkedlist;import java.util.NoSuchEleme.pdfpackage com.java2novice.ds.linkedlist;import java.util.NoSuchEleme.pdf
package com.java2novice.ds.linkedlist;import java.util.NoSuchEleme.pdf
ย 
Given below is the completed implementation of MyLinkedList class. O.pdf
Given below is the completed implementation of MyLinkedList class. O.pdfGiven below is the completed implementation of MyLinkedList class. O.pdf
Given below is the completed implementation of MyLinkedList class. O.pdf
ย 
Works Applications Test - Chinmay Chauhan
Works Applications Test - Chinmay ChauhanWorks Applications Test - Chinmay Chauhan
Works Applications Test - Chinmay Chauhan
ย 
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
ย 
public class MyLinkedListltE extends ComparableltEgtg.pdf
public class MyLinkedListltE extends ComparableltEgtg.pdfpublic class MyLinkedListltE extends ComparableltEgtg.pdf
public class MyLinkedListltE extends ComparableltEgtg.pdf
ย 
Help I keep getting the same error when running a code. Below is the.pdf
Help I keep getting the same error when running a code. Below is the.pdfHelp I keep getting the same error when running a code. Below is the.pdf
Help I keep getting the same error when running a code. Below is the.pdf
ย 
Hi,I have modified the Point.java file as per your requirement.P.pdf
Hi,I have modified the Point.java file as per your requirement.P.pdfHi,I have modified the Point.java file as per your requirement.P.pdf
Hi,I have modified the Point.java file as per your requirement.P.pdf
ย 
Solutionclass IntNode { int data; public IntNode next,head;.pdf
Solutionclass IntNode { int data; public IntNode next,head;.pdfSolutionclass IntNode { int data; public IntNode next,head;.pdf
Solutionclass IntNode { int data; public IntNode next,head;.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
ย 
output and explain There is Mylist There is MyArrayList pa.pdf
output and explain There is Mylist There is MyArrayList pa.pdfoutput and explain There is Mylist There is MyArrayList pa.pdf
output and explain There is Mylist There is MyArrayList pa.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
ย 
Complete the class ArraySet1java which implements the SetA.pdf
Complete the class ArraySet1java which implements the SetA.pdfComplete the class ArraySet1java which implements the SetA.pdf
Complete the class ArraySet1java which implements the SetA.pdf
ย 
Please finish everything marked TODO BinaryNode-java public class Bi.docx
Please finish everything marked TODO   BinaryNode-java public class Bi.docxPlease finish everything marked TODO   BinaryNode-java public class Bi.docx
Please finish everything marked TODO BinaryNode-java public class Bi.docx
ย 
Java ะฒะตัะฝะฐ 2013 ะปะตะบั†ะธั 2
Java ะฒะตัะฝะฐ 2013 ะปะตะบั†ะธั 2Java ะฒะตัะฝะฐ 2013 ะปะตะบั†ะธั 2
Java ะฒะตัะฝะฐ 2013 ะปะตะบั†ะธั 2
ย 
To complete the task, you need to fill in the missing code. Iโ€™ve inc.pdf
To complete the task, you need to fill in the missing code. Iโ€™ve inc.pdfTo complete the task, you need to fill in the missing code. Iโ€™ve inc.pdf
To complete the task, you need to fill in the missing code. Iโ€™ve inc.pdf
ย 
STAGE 2 The Methods 65 points Implement all the methods t.pdf
STAGE 2 The Methods 65 points Implement all the methods t.pdfSTAGE 2 The Methods 65 points Implement all the methods t.pdf
STAGE 2 The Methods 65 points Implement all the methods t.pdf
ย 
This is problem is same problem which i submitted on 22017, I just.pdf
This is problem is same problem which i submitted on 22017, I just.pdfThis is problem is same problem which i submitted on 22017, I just.pdf
This is problem is same problem which i submitted on 22017, I just.pdf
ย 
code#includeiostream using namespace std; class Point {.pdf
code#includeiostream using namespace std; class Point {.pdfcode#includeiostream using namespace std; class Point {.pdf
code#includeiostream using namespace std; class Point {.pdf
ย 

More from arcellzone

Part A List five 21st Century Skills you need to develop- Part B Ass.pdf
Part A List five 21st Century Skills you need to develop-   Part B Ass.pdfPart A List five 21st Century Skills you need to develop-   Part B Ass.pdf
Part A List five 21st Century Skills you need to develop- Part B Ass.pdf
arcellzone
ย 
package linkedLists- import java-util-Iterator- --- A class representi.pdf
package linkedLists- import java-util-Iterator- --- A class representi.pdfpackage linkedLists- import java-util-Iterator- --- A class representi.pdf
package linkedLists- import java-util-Iterator- --- A class representi.pdf
arcellzone
ย 
package hw1-public class Runner { public static void main(String-- arg (1).pdf
package hw1-public class Runner { public static void main(String-- arg (1).pdfpackage hw1-public class Runner { public static void main(String-- arg (1).pdf
package hw1-public class Runner { public static void main(String-- arg (1).pdf
arcellzone
ย 

More from arcellzone (20)

Part A List five 21st Century Skills you need to develop- Part B Ass.pdf
Part A List five 21st Century Skills you need to develop-   Part B Ass.pdfPart A List five 21st Century Skills you need to develop-   Part B Ass.pdf
Part A List five 21st Century Skills you need to develop- Part B Ass.pdf
ย 
Part 5- Use the 105CLl to Gather Device Information (10 points) Issue.pdf
Part 5- Use the 105CLl to Gather Device Information (10 points) Issue.pdfPart 5- Use the 105CLl to Gather Device Information (10 points) Issue.pdf
Part 5- Use the 105CLl to Gather Device Information (10 points) Issue.pdf
ย 
Part 8- Use the simplified sum-of-minterms expressions to generate the (1).pdf
Part 8- Use the simplified sum-of-minterms expressions to generate the (1).pdfPart 8- Use the simplified sum-of-minterms expressions to generate the (1).pdf
Part 8- Use the simplified sum-of-minterms expressions to generate the (1).pdf
ย 
Part 2- Character -- Reminder- all data objects should have getters an.pdf
Part 2- Character -- Reminder- all data objects should have getters an.pdfPart 2- Character -- Reminder- all data objects should have getters an.pdf
Part 2- Character -- Reminder- all data objects should have getters an.pdf
ย 
Part 1- Research the Importance of an IT Asset Inventory Conduct an in.pdf
Part 1- Research the Importance of an IT Asset Inventory Conduct an in.pdfPart 1- Research the Importance of an IT Asset Inventory Conduct an in.pdf
Part 1- Research the Importance of an IT Asset Inventory Conduct an in.pdf
ย 
Part 2 Water Trace a molecule of water from the renal artery to the re.pdf
Part 2 Water Trace a molecule of water from the renal artery to the re.pdfPart 2 Water Trace a molecule of water from the renal artery to the re.pdf
Part 2 Water Trace a molecule of water from the renal artery to the re.pdf
ย 
Part 2 1- Create a list of all the IP addresses used to attempt to log.pdf
Part 2 1- Create a list of all the IP addresses used to attempt to log.pdfPart 2 1- Create a list of all the IP addresses used to attempt to log.pdf
Part 2 1- Create a list of all the IP addresses used to attempt to log.pdf
ย 
Part 11 atratighisini and youngist will the in lith- thery are fiponit.pdf
Part 11 atratighisini and youngist will the in lith- thery are fiponit.pdfPart 11 atratighisini and youngist will the in lith- thery are fiponit.pdf
Part 11 atratighisini and youngist will the in lith- thery are fiponit.pdf
ย 
Parsing food data lab - Please answer in JAVA Given a text file contai.pdf
Parsing food data lab - Please answer in JAVA Given a text file contai.pdfParsing food data lab - Please answer in JAVA Given a text file contai.pdf
Parsing food data lab - Please answer in JAVA Given a text file contai.pdf
ย 
Paris Just Got Cheaper for American Tourists Paris- France- Americans.pdf
Paris Just Got Cheaper for American Tourists Paris- France- Americans.pdfParis Just Got Cheaper for American Tourists Paris- France- Americans.pdf
Paris Just Got Cheaper for American Tourists Paris- France- Americans.pdf
ย 
Parent generation Cross-fertilization F1 generation F2 generationRead.pdf
Parent generation Cross-fertilization F1 generation F2 generationRead.pdfParent generation Cross-fertilization F1 generation F2 generationRead.pdf
Parent generation Cross-fertilization F1 generation F2 generationRead.pdf
ย 
Paf is a small country- Its currency is the pif- and the exchange rate.pdf
Paf is a small country- Its currency is the pif- and the exchange rate.pdfPaf is a small country- Its currency is the pif- and the exchange rate.pdf
Paf is a small country- Its currency is the pif- and the exchange rate.pdf
ย 
package linkedLists- import java-util-Iterator- --- A class representi.pdf
package linkedLists- import java-util-Iterator- --- A class representi.pdfpackage linkedLists- import java-util-Iterator- --- A class representi.pdf
package linkedLists- import java-util-Iterator- --- A class representi.pdf
ย 
package hw1-public class Runner { public static void main(String-- arg (1).pdf
package hw1-public class Runner { public static void main(String-- arg (1).pdfpackage hw1-public class Runner { public static void main(String-- arg (1).pdf
package hw1-public class Runner { public static void main(String-- arg (1).pdf
ย 
P1) Given the Von Neumann architecture- answer the following questions.pdf
P1) Given the Von Neumann architecture- answer the following questions.pdfP1) Given the Von Neumann architecture- answer the following questions.pdf
P1) Given the Von Neumann architecture- answer the following questions.pdf
ย 
P1) Answer the following questions (a) We discussed about bottleneck i.pdf
P1) Answer the following questions (a) We discussed about bottleneck i.pdfP1) Answer the following questions (a) We discussed about bottleneck i.pdf
P1) Answer the following questions (a) We discussed about bottleneck i.pdf
ย 
P1) Answer the following questions ( 40 points) (a) We discussed about.pdf
P1) Answer the following questions ( 40 points) (a) We discussed about.pdfP1) Answer the following questions ( 40 points) (a) We discussed about.pdf
P1) Answer the following questions ( 40 points) (a) We discussed about.pdf
ย 
Our Space is a social media site that is growing in popularity- The fi.pdf
Our Space is a social media site that is growing in popularity- The fi.pdfOur Space is a social media site that is growing in popularity- The fi.pdf
Our Space is a social media site that is growing in popularity- The fi.pdf
ย 
P(Zn-kZn1-j)-k!(j)kej (5 points) Let T be the minimal value of n such.pdf
P(Zn-kZn1-j)-k!(j)kej (5 points) Let T be the minimal value of n such.pdfP(Zn-kZn1-j)-k!(j)kej (5 points) Let T be the minimal value of n such.pdf
P(Zn-kZn1-j)-k!(j)kej (5 points) Let T be the minimal value of n such.pdf
ย 
P(Zn-kZn1-j)-k!(j)kejfn-P(T-10Z1-n)gn-P(T-20Z1-n).pdf
P(Zn-kZn1-j)-k!(j)kejfn-P(T-10Z1-n)gn-P(T-20Z1-n).pdfP(Zn-kZn1-j)-k!(j)kejfn-P(T-10Z1-n)gn-P(T-20Z1-n).pdf
P(Zn-kZn1-j)-k!(j)kejfn-P(T-10Z1-n)gn-P(T-20Z1-n).pdf
ย 

Recently uploaded

Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
KarakKing
ย 

Recently uploaded (20)

How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
ย 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
ย 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
ย 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
ย 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
ย 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
ย 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
ย 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
ย 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
ย 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
ย 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
ย 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
ย 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
ย 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
ย 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
ย 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
ย 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptx
ย 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
ย 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
ย 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
ย 

package ex2- public class Exercise2-E- { private static class N.pdf

  • 1. package ex2; public class Exercise2<E> { private static class Node<E> { private E element; private Node<E> prev; private Node<E> next; public Node(E e, Node<E> p, Node<E> n) { element = e; prev = p; next = n; } public E getElement() { return element; } public Node<E> getPrev() { return prev; } public Node<E> getNext() { return next; } public void setPrev(Node<E> p) { prev = p; } public void setNext(Node<E> n) { next = n; } } private Node<E> header; private Node<E> trailer; private int size = 0; public Exercise2() { header = new Node<>(null, null, null); trailer = new Node<>(null, header, null); header.setNext(trailer); } public int size() { return size; } public boolean isEmpty() { return size == 0; } public E first() { if (isEmpty()) return null; return header.getNext().getElement(); } public E last() { if (isEmpty()) return null; return trailer.getPrev().getElement(); }
  • 2. public void addFirst(E e) { addBetween(e, header, header.getNext()); } public void addLast(E e) { addBetween(e, trailer.getPrev(), trailer); } public E removeFirst() { if (isEmpty()) return null; return remove(header.getNext()); } public E removeLast() { if (isEmpty()) return null; return remove(trailer.getPrev()); } private void addBetween(E e, Node<E> predecessor, Node<E> successor) { if (predecessor == header && successor == trailer) { // skip creation of new node for header/trailer header.setNext(new Node<>(e, header, trailer)); trailer.setPrev(header.getNext()); } else { Node<E> newest = new Node<>(e, predecessor, successor); predecessor.setNext(newest); successor.setPrev(newest); } size++; } private E remove(Node<E> node) { Node<E> predecessor = node.getPrev(); Node<E> successor = node.getNext(); predecessor.setNext(successor); successor.setPrev(predecessor); size--; return node.getElement(); } public String toString() { StringBuilder sb = new StringBuilder("("); Node<E> walk = header; while (walk != null) { sb.append(walk.getElement()); walk = walk.getNext();
  • 3. if (walk != null) { sb.append(", "); } } sb.append(")"); return sb.toString(); } public void reverseList() { Node<E> current = header; header = trailer.getPrev(); trailer = current.getNext(); while (current != null) { Node<E> temp = current.getNext(); current.setNext(current.getPrev()); current.setPrev(temp); current = temp; } } public static void main(String[] args) { Exercise2<String> list = new Exercise2<String>(); list.addFirst("MSP"); list.addLast("ATL"); list.addLast("BOS"); list.addFirst("LAX"); System.out.println(list); list.reverseList(); System.out.println(list); } } Here's my code, the output should reverse the list, but I'm keep getting errors, anyone mind to help me to get a proper output?