SlideShare a Scribd company logo
Create a new java class called ListNode. Implement ListNode as a generic version of IntNode.
public class ListNode { }
Create a generic class called Queue, which is a linked list implementation of a queue data type.
Queue must have the following methods:
• public void enqueue(T value){} This method should add a new node to the back of the queue.
• public T dequeue(){} This method should remove a node from the front of the queue and return
its value
• public T peek(){} This method should return the value of the front node without removing it
from the queue
Create a new generic class called Stack, which is a linked list implementation of a stack data
type. Stack must have the following methods:
• public void push(T value){} This method should add a new node to the top of the stack.
• public T pop(){} This method should remove a node from the top of the stack and return its
integer value
• public T peek(){} This method should return the integer value of the top node without
removing it from the stack
Solution
import java.util.Iterator;
public class LinkedList extends AbstractList {
private ListNode front; // refers to first node in list (null if empty)
public LinkedList() {
front = null; // null front means empty
}
public void add(int index, E value) {
if (index == 0) {
// insert at the front
front = new ListNode(value, front);
} else {
ListNode current = goTo(index - 1);
ListNode newNode = new ListNode(value, current.next);
current.next = newNode;
}
}
public E get(int index) {
ListNode current = goTo(index);
return current.data;
}
public int indexOf(E value) {
int index = 0;
ListNode current = front;
while (current != null) {
if (current.data == value) {
return index;
}
index++;
current = current.next;
}
return -1;
}
public Iterator iterator() {
return new LinkedListIterator();
}
public void remove(int index) {
if (index == 0) {
// removing from the front
front = front.next;
} else {
ListNode current = goTo(index - 1);
current.next = current.next.next; // deletes the node
}
}
public void set(int index, E value) {
ListNode current = goTo(index);
current.data = value;
}
public int size() {
int count = 0;
ListNode current = front;
while (current != null) {
current = current.next;
count++;
}
return count;
}
public String toString() {
if (front == null) {
return "[]";
} else {
String result = "[" + front.data;
ListNode current = front.next;
while (current != null) {
result += ", " + current.data;
current = current.next;
}
result += "]";
return result;
}
}
private ListNode goTo(int index) {
ListNode current = front;
for (int i = 0; i < index; i++) {
current = current.next;
}
return current;
}
public class ListNode {
public E data;
public ListNode next;
public ListNode(E data) {
this.data = data;
this.next = null;
}
public ListNode(E data, ListNode next) {
this.data = data;
this.next = next;
}
}
private class LinkedListIterator implements Iterator {
private ListNode current; // current position in list
public LinkedListIterator() {
current = front;
}
public boolean hasNext() {
return current != null;
}
public E next() {
E result = current.data;
current = current.next;
return result;
}
public void remove() {
throw new UnsupportedOperationException();
}
}
}
Ad

Recommended

Here is the editable codeSolutionimport java.util.NoSuchEleme.pdf
Here is the editable codeSolutionimport java.util.NoSuchEleme.pdf
arrowmobile
 
Rewrite this code so it can use a generic type instead of integers. .pdf
Rewrite this code so it can use a generic type instead of integers. .pdf
alphaagenciesindia
 
PLEASE MAKE SURE THE PROGRAM IS ASKING FOR INPUT FROM USER TO ADD OR.pdf
PLEASE MAKE SURE THE PROGRAM IS ASKING FOR INPUT FROM USER TO ADD OR.pdf
mallik3000
 
For each task, submit your source java code file.(1) Objective Im.pdf
For each task, submit your source java code file.(1) Objective Im.pdf
dhavalbl38
 
STAGE 2 The Methods 65 points Implement all the methods t.pdf
STAGE 2 The Methods 65 points Implement all the methods t.pdf
babitasingh698417
 
Implement the interface you wrote for Lab B (EntryWayListInterface)..pdf
Implement the interface you wrote for Lab B (EntryWayListInterface)..pdf
rishabjain5053
 
Write a Java Class to Implement a Generic Linked ListYour list mus.pdf
Write a Java Class to Implement a Generic Linked ListYour list mus.pdf
rozakashif85
 
Objective The purpose of this exercise is to create a Linked List d.pdf
Objective The purpose of this exercise is to create a Linked List d.pdf
aliracreations
 
Objective The purpose of this exercise is to create a Linke.pdf
Objective The purpose of this exercise is to create a Linke.pdf
advancethchnologies
 
Objective The purpose of this exercise is to create a Linke.pdf
Objective The purpose of this exercise is to create a Linke.pdf
giriraj65
 
Please and Thank youObjective The purpose of this exercise is to .pdf
Please and Thank youObjective The purpose of this exercise is to .pdf
alicesilverblr
 
Linked List Objective The purpose of this exercise is to cr.pdf
Linked List Objective The purpose of this exercise is to cr.pdf
adityacomputers001
 
Given below is the completed implementation of MyLinkedList class. O.pdf
Given below is the completed implementation of MyLinkedList class. O.pdf
info430661
 
In this lab, we will write an application to store a deck of cards i.pdf
In this lab, we will write an application to store a deck of cards i.pdf
contact41
 
public class MyLinkedListltE extends ComparableltEgtg.pdf
public class MyLinkedListltE extends ComparableltEgtg.pdf
accostinternational
 
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
freddysarabia1
 
Use the singly linked list class introduced in the lab to implement .pdf
Use the singly linked list class introduced in the lab to implement .pdf
sales87
 
Java AssignmentUsing the ListNode.java file below Write method.pdf
Java AssignmentUsing the ListNode.java file below Write method.pdf
ambersushil
 
The LinkedList1 class implements a Linked list. class.pdf
The LinkedList1 class implements a Linked list. class.pdf
malavshah9013
 
Hi,I have added the methods and main class as per your requirement.pdf
Hi,I have added the methods and main class as per your requirement.pdf
annaelctronics
 
Class DiagramIn the Assignment #10, you are given three files Ass.pdf
Class DiagramIn the Assignment #10, you are given three files Ass.pdf
xlynettalampleyxc
 
-JAVA-provide a test class that do the required -you may add met.pdf
-JAVA-provide a test class that do the required -you may add met.pdf
alphawheels007
 
import java-util--- public class MyLinkedList{ public static void.pdf
import java-util--- public class MyLinkedList{ public static void.pdf
asarudheen07
 
I need help implementing a Stack with this java programming assignme.pdf
I need help implementing a Stack with this java programming assignme.pdf
sauravmanwanicp
 
Copy your completed LinkedList class from Lab 3 into the LinkedList..pdf
Copy your completed LinkedList class from Lab 3 into the LinkedList..pdf
facevenky
 
Implementation The starter code includes List.java. You should not c.pdf
Implementation The starter code includes List.java. You should not c.pdf
maheshkumar12354
 
File LinkedList.java Defines a doubly-l.pdf
File LinkedList.java Defines a doubly-l.pdf
Conint29
 
Using visual studio 2022- a C# windows form application- and your Doub.pdf
Using visual studio 2022- a C# windows form application- and your Doub.pdf
acteleshoppe
 
Which of the following characteristics of living organisms absolutel.pdf
Which of the following characteristics of living organisms absolutel.pdf
mohamednihalshahru
 
What influence does the presence of alloying elements (other than ca.pdf
What influence does the presence of alloying elements (other than ca.pdf
mohamednihalshahru
 

More Related Content

Similar to Create a new java class called ListNode. Implement ListNode as a gen.pdf (20)

Objective The purpose of this exercise is to create a Linke.pdf
Objective The purpose of this exercise is to create a Linke.pdf
advancethchnologies
 
Objective The purpose of this exercise is to create a Linke.pdf
Objective The purpose of this exercise is to create a Linke.pdf
giriraj65
 
Please and Thank youObjective The purpose of this exercise is to .pdf
Please and Thank youObjective The purpose of this exercise is to .pdf
alicesilverblr
 
Linked List Objective The purpose of this exercise is to cr.pdf
Linked List Objective The purpose of this exercise is to cr.pdf
adityacomputers001
 
Given below is the completed implementation of MyLinkedList class. O.pdf
Given below is the completed implementation of MyLinkedList class. O.pdf
info430661
 
In this lab, we will write an application to store a deck of cards i.pdf
In this lab, we will write an application to store a deck of cards i.pdf
contact41
 
public class MyLinkedListltE extends ComparableltEgtg.pdf
public class MyLinkedListltE extends ComparableltEgtg.pdf
accostinternational
 
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
freddysarabia1
 
Use the singly linked list class introduced in the lab to implement .pdf
Use the singly linked list class introduced in the lab to implement .pdf
sales87
 
Java AssignmentUsing the ListNode.java file below Write method.pdf
Java AssignmentUsing the ListNode.java file below Write method.pdf
ambersushil
 
The LinkedList1 class implements a Linked list. class.pdf
The LinkedList1 class implements a Linked list. class.pdf
malavshah9013
 
Hi,I have added the methods and main class as per your requirement.pdf
Hi,I have added the methods and main class as per your requirement.pdf
annaelctronics
 
Class DiagramIn the Assignment #10, you are given three files Ass.pdf
Class DiagramIn the Assignment #10, you are given three files Ass.pdf
xlynettalampleyxc
 
-JAVA-provide a test class that do the required -you may add met.pdf
-JAVA-provide a test class that do the required -you may add met.pdf
alphawheels007
 
import java-util--- public class MyLinkedList{ public static void.pdf
import java-util--- public class MyLinkedList{ public static void.pdf
asarudheen07
 
I need help implementing a Stack with this java programming assignme.pdf
I need help implementing a Stack with this java programming assignme.pdf
sauravmanwanicp
 
Copy your completed LinkedList class from Lab 3 into the LinkedList..pdf
Copy your completed LinkedList class from Lab 3 into the LinkedList..pdf
facevenky
 
Implementation The starter code includes List.java. You should not c.pdf
Implementation The starter code includes List.java. You should not c.pdf
maheshkumar12354
 
File LinkedList.java Defines a doubly-l.pdf
File LinkedList.java Defines a doubly-l.pdf
Conint29
 
Using visual studio 2022- a C# windows form application- and your Doub.pdf
Using visual studio 2022- a C# windows form application- and your Doub.pdf
acteleshoppe
 
Objective The purpose of this exercise is to create a Linke.pdf
Objective The purpose of this exercise is to create a Linke.pdf
advancethchnologies
 
Objective The purpose of this exercise is to create a Linke.pdf
Objective The purpose of this exercise is to create a Linke.pdf
giriraj65
 
Please and Thank youObjective The purpose of this exercise is to .pdf
Please and Thank youObjective The purpose of this exercise is to .pdf
alicesilverblr
 
Linked List Objective The purpose of this exercise is to cr.pdf
Linked List Objective The purpose of this exercise is to cr.pdf
adityacomputers001
 
Given below is the completed implementation of MyLinkedList class. O.pdf
Given below is the completed implementation of MyLinkedList class. O.pdf
info430661
 
In this lab, we will write an application to store a deck of cards i.pdf
In this lab, we will write an application to store a deck of cards i.pdf
contact41
 
public class MyLinkedListltE extends ComparableltEgtg.pdf
public class MyLinkedListltE extends ComparableltEgtg.pdf
accostinternational
 
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
freddysarabia1
 
Use the singly linked list class introduced in the lab to implement .pdf
Use the singly linked list class introduced in the lab to implement .pdf
sales87
 
Java AssignmentUsing the ListNode.java file below Write method.pdf
Java AssignmentUsing the ListNode.java file below Write method.pdf
ambersushil
 
The LinkedList1 class implements a Linked list. class.pdf
The LinkedList1 class implements a Linked list. class.pdf
malavshah9013
 
Hi,I have added the methods and main class as per your requirement.pdf
Hi,I have added the methods and main class as per your requirement.pdf
annaelctronics
 
Class DiagramIn the Assignment #10, you are given three files Ass.pdf
Class DiagramIn the Assignment #10, you are given three files Ass.pdf
xlynettalampleyxc
 
-JAVA-provide a test class that do the required -you may add met.pdf
-JAVA-provide a test class that do the required -you may add met.pdf
alphawheels007
 
import java-util--- public class MyLinkedList{ public static void.pdf
import java-util--- public class MyLinkedList{ public static void.pdf
asarudheen07
 
I need help implementing a Stack with this java programming assignme.pdf
I need help implementing a Stack with this java programming assignme.pdf
sauravmanwanicp
 
Copy your completed LinkedList class from Lab 3 into the LinkedList..pdf
Copy your completed LinkedList class from Lab 3 into the LinkedList..pdf
facevenky
 
Implementation The starter code includes List.java. You should not c.pdf
Implementation The starter code includes List.java. You should not c.pdf
maheshkumar12354
 
File LinkedList.java Defines a doubly-l.pdf
File LinkedList.java Defines a doubly-l.pdf
Conint29
 
Using visual studio 2022- a C# windows form application- and your Doub.pdf
Using visual studio 2022- a C# windows form application- and your Doub.pdf
acteleshoppe
 

More from mohamednihalshahru (20)

Which of the following characteristics of living organisms absolutel.pdf
Which of the following characteristics of living organisms absolutel.pdf
mohamednihalshahru
 
What influence does the presence of alloying elements (other than ca.pdf
What influence does the presence of alloying elements (other than ca.pdf
mohamednihalshahru
 
Two very long uniformly charged lines (with linear charge densities i.pdf
Two very long uniformly charged lines (with linear charge densities i.pdf
mohamednihalshahru
 
there is a serious outbreak of staph aureus in the hospital. A conve.pdf
there is a serious outbreak of staph aureus in the hospital. A conve.pdf
mohamednihalshahru
 
Timer Notes obiect and the dashed arrow the image. The rectangle show.pdf
Timer Notes obiect and the dashed arrow the image. The rectangle show.pdf
mohamednihalshahru
 
Representatives from four different colleges of UM- Dearborn will be .pdf
Representatives from four different colleges of UM- Dearborn will be .pdf
mohamednihalshahru
 
Problem asks me to prove Uniqueness but Im not sure how to do it! .pdf
Problem asks me to prove Uniqueness but Im not sure how to do it! .pdf
mohamednihalshahru
 
please send edited codeMain.javapackage part2;import java.util.pdf
please send edited codeMain.javapackage part2;import java.util.pdf
mohamednihalshahru
 
Inhaling and exhaling Label the figure that shows INHALATION and.pdf
Inhaling and exhaling Label the figure that shows INHALATION and.pdf
mohamednihalshahru
 
In accordance to the PLSS land description system, locate the section.pdf
In accordance to the PLSS land description system, locate the section.pdf
mohamednihalshahru
 
How can a topologically associating domain (TAD) mutation effect mor.pdf
How can a topologically associating domain (TAD) mutation effect mor.pdf
mohamednihalshahru
 
Hello, I need help writing a code in C. It wants to do things with f.pdf
Hello, I need help writing a code in C. It wants to do things with f.pdf
mohamednihalshahru
 
Fix the following C program in linux. When it is compiled it gives t.pdf
Fix the following C program in linux. When it is compiled it gives t.pdf
mohamednihalshahru
 
7. Wet ear wax (W) is dominant over dry ear wax (w)W=wet ear wax.pdf
7. Wet ear wax (W) is dominant over dry ear wax (w)W=wet ear wax.pdf
mohamednihalshahru
 
Examine your opinion on the death penalty. Defend why you are for th.pdf
Examine your opinion on the death penalty. Defend why you are for th.pdf
mohamednihalshahru
 
Do you think that knowing about aggression between groups of chimpan.pdf
Do you think that knowing about aggression between groups of chimpan.pdf
mohamednihalshahru
 
Diana’s Death UnraveledHemophilia causes a lack of blood clotting,.pdf
Diana’s Death UnraveledHemophilia causes a lack of blood clotting,.pdf
mohamednihalshahru
 
Complete the following short answer questions1.  How do the virus.pdf
Complete the following short answer questions1.  How do the virus.pdf
mohamednihalshahru
 
Briefly describe the two competing theories regarding the origin of H.pdf
Briefly describe the two competing theories regarding the origin of H.pdf
mohamednihalshahru
 
Atlas Advertising Atlas Advertising is a regional advertising agency.pdf
Atlas Advertising Atlas Advertising is a regional advertising agency.pdf
mohamednihalshahru
 
Which of the following characteristics of living organisms absolutel.pdf
Which of the following characteristics of living organisms absolutel.pdf
mohamednihalshahru
 
What influence does the presence of alloying elements (other than ca.pdf
What influence does the presence of alloying elements (other than ca.pdf
mohamednihalshahru
 
Two very long uniformly charged lines (with linear charge densities i.pdf
Two very long uniformly charged lines (with linear charge densities i.pdf
mohamednihalshahru
 
there is a serious outbreak of staph aureus in the hospital. A conve.pdf
there is a serious outbreak of staph aureus in the hospital. A conve.pdf
mohamednihalshahru
 
Timer Notes obiect and the dashed arrow the image. The rectangle show.pdf
Timer Notes obiect and the dashed arrow the image. The rectangle show.pdf
mohamednihalshahru
 
Representatives from four different colleges of UM- Dearborn will be .pdf
Representatives from four different colleges of UM- Dearborn will be .pdf
mohamednihalshahru
 
Problem asks me to prove Uniqueness but Im not sure how to do it! .pdf
Problem asks me to prove Uniqueness but Im not sure how to do it! .pdf
mohamednihalshahru
 
please send edited codeMain.javapackage part2;import java.util.pdf
please send edited codeMain.javapackage part2;import java.util.pdf
mohamednihalshahru
 
Inhaling and exhaling Label the figure that shows INHALATION and.pdf
Inhaling and exhaling Label the figure that shows INHALATION and.pdf
mohamednihalshahru
 
In accordance to the PLSS land description system, locate the section.pdf
In accordance to the PLSS land description system, locate the section.pdf
mohamednihalshahru
 
How can a topologically associating domain (TAD) mutation effect mor.pdf
How can a topologically associating domain (TAD) mutation effect mor.pdf
mohamednihalshahru
 
Hello, I need help writing a code in C. It wants to do things with f.pdf
Hello, I need help writing a code in C. It wants to do things with f.pdf
mohamednihalshahru
 
Fix the following C program in linux. When it is compiled it gives t.pdf
Fix the following C program in linux. When it is compiled it gives t.pdf
mohamednihalshahru
 
7. Wet ear wax (W) is dominant over dry ear wax (w)W=wet ear wax.pdf
7. Wet ear wax (W) is dominant over dry ear wax (w)W=wet ear wax.pdf
mohamednihalshahru
 
Examine your opinion on the death penalty. Defend why you are for th.pdf
Examine your opinion on the death penalty. Defend why you are for th.pdf
mohamednihalshahru
 
Do you think that knowing about aggression between groups of chimpan.pdf
Do you think that knowing about aggression between groups of chimpan.pdf
mohamednihalshahru
 
Diana’s Death UnraveledHemophilia causes a lack of blood clotting,.pdf
Diana’s Death UnraveledHemophilia causes a lack of blood clotting,.pdf
mohamednihalshahru
 
Complete the following short answer questions1.  How do the virus.pdf
Complete the following short answer questions1.  How do the virus.pdf
mohamednihalshahru
 
Briefly describe the two competing theories regarding the origin of H.pdf
Briefly describe the two competing theories regarding the origin of H.pdf
mohamednihalshahru
 
Atlas Advertising Atlas Advertising is a regional advertising agency.pdf
Atlas Advertising Atlas Advertising is a regional advertising agency.pdf
mohamednihalshahru
 
Ad

Recently uploaded (20)

Exploring Ocean Floor Features for Middle School
Exploring Ocean Floor Features for Middle School
Marie
 
Ray Dalio How Countries go Broke the Big Cycle
Ray Dalio How Countries go Broke the Big Cycle
Dadang Solihin
 
Paper 109 | Archetypal Journeys in ‘Interstellar’: Exploring Universal Themes...
Paper 109 | Archetypal Journeys in ‘Interstellar’: Exploring Universal Themes...
Rajdeep Bavaliya
 
BINARY files CSV files JSON files with example.pptx
BINARY files CSV files JSON files with example.pptx
Ramakrishna Reddy Bijjam
 
Measuring, learning and applying multiplication facts.
Measuring, learning and applying multiplication facts.
cgilmore6
 
Wax Moon, Richmond, VA. Terrence McPherson
Wax Moon, Richmond, VA. Terrence McPherson
TerrenceMcPherson1
 
Revista digital preescolar en transformación
Revista digital preescolar en transformación
guerragallardo26
 
How to Implement Least Package Removal Strategy in Odoo 18 Inventory
How to Implement Least Package Removal Strategy in Odoo 18 Inventory
Celine George
 
FIRST DAY HIGH orientation for mapeh subject in grade 10.pptx
FIRST DAY HIGH orientation for mapeh subject in grade 10.pptx
GlysdiEelesor1
 
How to Manage Multi Language for Invoice in Odoo 18
How to Manage Multi Language for Invoice in Odoo 18
Celine George
 
FEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdf
FEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdf
ChristinaFortunova
 
ABCs of Bookkeeping for Nonprofits TechSoup.pdf
ABCs of Bookkeeping for Nonprofits TechSoup.pdf
TechSoup
 
Overview of Employee in Odoo 18 - Odoo Slides
Overview of Employee in Odoo 18 - Odoo Slides
Celine George
 
Capitol Doctoral Presentation -June 2025.pptx
Capitol Doctoral Presentation -June 2025.pptx
CapitolTechU
 
ROLE PLAY: FIRST AID -CPR & RECOVERY POSITION.pptx
ROLE PLAY: FIRST AID -CPR & RECOVERY POSITION.pptx
Belicia R.S
 
BUSINESS QUIZ PRELIMS | QUIZ CLUB OF PSGCAS | 9 SEPTEMBER 2024
BUSINESS QUIZ PRELIMS | QUIZ CLUB OF PSGCAS | 9 SEPTEMBER 2024
Quiz Club of PSG College of Arts & Science
 
Assisting Individuals and Families to Promote and Maintain Health – Unit 7 | ...
Assisting Individuals and Families to Promote and Maintain Health – Unit 7 | ...
RAKESH SAJJAN
 
How to Manage Upselling of Subscriptions in Odoo 18
How to Manage Upselling of Subscriptions in Odoo 18
Celine George
 
How to Manage Inventory Movement in Odoo 18 POS
How to Manage Inventory Movement in Odoo 18 POS
Celine George
 
THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...
THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...
parmarjuli1412
 
Exploring Ocean Floor Features for Middle School
Exploring Ocean Floor Features for Middle School
Marie
 
Ray Dalio How Countries go Broke the Big Cycle
Ray Dalio How Countries go Broke the Big Cycle
Dadang Solihin
 
Paper 109 | Archetypal Journeys in ‘Interstellar’: Exploring Universal Themes...
Paper 109 | Archetypal Journeys in ‘Interstellar’: Exploring Universal Themes...
Rajdeep Bavaliya
 
BINARY files CSV files JSON files with example.pptx
BINARY files CSV files JSON files with example.pptx
Ramakrishna Reddy Bijjam
 
Measuring, learning and applying multiplication facts.
Measuring, learning and applying multiplication facts.
cgilmore6
 
Wax Moon, Richmond, VA. Terrence McPherson
Wax Moon, Richmond, VA. Terrence McPherson
TerrenceMcPherson1
 
Revista digital preescolar en transformación
Revista digital preescolar en transformación
guerragallardo26
 
How to Implement Least Package Removal Strategy in Odoo 18 Inventory
How to Implement Least Package Removal Strategy in Odoo 18 Inventory
Celine George
 
FIRST DAY HIGH orientation for mapeh subject in grade 10.pptx
FIRST DAY HIGH orientation for mapeh subject in grade 10.pptx
GlysdiEelesor1
 
How to Manage Multi Language for Invoice in Odoo 18
How to Manage Multi Language for Invoice in Odoo 18
Celine George
 
FEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdf
FEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdf
ChristinaFortunova
 
ABCs of Bookkeeping for Nonprofits TechSoup.pdf
ABCs of Bookkeeping for Nonprofits TechSoup.pdf
TechSoup
 
Overview of Employee in Odoo 18 - Odoo Slides
Overview of Employee in Odoo 18 - Odoo Slides
Celine George
 
Capitol Doctoral Presentation -June 2025.pptx
Capitol Doctoral Presentation -June 2025.pptx
CapitolTechU
 
ROLE PLAY: FIRST AID -CPR & RECOVERY POSITION.pptx
ROLE PLAY: FIRST AID -CPR & RECOVERY POSITION.pptx
Belicia R.S
 
Assisting Individuals and Families to Promote and Maintain Health – Unit 7 | ...
Assisting Individuals and Families to Promote and Maintain Health – Unit 7 | ...
RAKESH SAJJAN
 
How to Manage Upselling of Subscriptions in Odoo 18
How to Manage Upselling of Subscriptions in Odoo 18
Celine George
 
How to Manage Inventory Movement in Odoo 18 POS
How to Manage Inventory Movement in Odoo 18 POS
Celine George
 
THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...
THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...
parmarjuli1412
 
Ad

Create a new java class called ListNode. Implement ListNode as a gen.pdf

  • 1. Create a new java class called ListNode. Implement ListNode as a generic version of IntNode. public class ListNode { } Create a generic class called Queue, which is a linked list implementation of a queue data type. Queue must have the following methods: • public void enqueue(T value){} This method should add a new node to the back of the queue. • public T dequeue(){} This method should remove a node from the front of the queue and return its value • public T peek(){} This method should return the value of the front node without removing it from the queue Create a new generic class called Stack, which is a linked list implementation of a stack data type. Stack must have the following methods: • public void push(T value){} This method should add a new node to the top of the stack. • public T pop(){} This method should remove a node from the top of the stack and return its integer value • public T peek(){} This method should return the integer value of the top node without removing it from the stack Solution import java.util.Iterator; public class LinkedList extends AbstractList { private ListNode front; // refers to first node in list (null if empty) public LinkedList() { front = null; // null front means empty } public void add(int index, E value) { if (index == 0) { // insert at the front front = new ListNode(value, front); } else { ListNode current = goTo(index - 1); ListNode newNode = new ListNode(value, current.next);
  • 2. current.next = newNode; } } public E get(int index) { ListNode current = goTo(index); return current.data; } public int indexOf(E value) { int index = 0; ListNode current = front; while (current != null) { if (current.data == value) { return index; } index++; current = current.next; } return -1; } public Iterator iterator() { return new LinkedListIterator(); } public void remove(int index) { if (index == 0) { // removing from the front front = front.next; } else { ListNode current = goTo(index - 1);
  • 3. current.next = current.next.next; // deletes the node } } public void set(int index, E value) { ListNode current = goTo(index); current.data = value; } public int size() { int count = 0; ListNode current = front; while (current != null) { current = current.next; count++; } return count; } public String toString() { if (front == null) { return "[]"; } else { String result = "[" + front.data; ListNode current = front.next; while (current != null) { result += ", " + current.data; current = current.next; } result += "]"; return result; } }
  • 4. private ListNode goTo(int index) { ListNode current = front; for (int i = 0; i < index; i++) { current = current.next; } return current; } public class ListNode { public E data; public ListNode next; public ListNode(E data) { this.data = data; this.next = null; } public ListNode(E data, ListNode next) { this.data = data; this.next = next; } } private class LinkedListIterator implements Iterator { private ListNode current; // current position in list public LinkedListIterator() { current = front; } public boolean hasNext() { return current != null; } public E next() { E result = current.data; current = current.next; return result;
  • 5. } public void remove() { throw new UnsupportedOperationException(); } } }