SlideShare a Scribd company logo
1 of 3
Download to read offline
Select three methods in the ObjectList class to work through algorithmically. Describe any
special cases or boundary conditions that might exist for each of the three methods selected. Be
sure to draw pictures as you work through the methods. Remember that you cannot work on
linked lists without drawing pictures. The homework will not be accepted without submitting the
pictures! Write a Java method with the signature: public objectList intersect (objectList list1,
objectList list2) that accepts two unordered linear linked lists and returns a third linear linked list
whose nodes contains the intersection of the two original linear linked lists. Note that the
intersection of two lists is a new list containing the elements that the two lists have in common,
without modifying the two original lists. Describe any boundary conditions that might exist.
Solution
Node.java
//Defines each node of a linked list
public class Node{
int data;
Node next;
Node(int d)
{
data = d;
next = null;
}
}
ObjectList.java
public class ObjectList{
public Node head;
/* Utility function to print list */
public void printList()
{
Node temp = head;
while(temp != null)
{
System.out.print(temp.data+" ");
temp = temp.next;
}
System.out.println();
}
/* Inserts a node at start of linked list */
public void push(int new_data)
{
/* 1 & 2: Allocate the Node &
Put in the data*/
Node new_node = new Node(new_data);
/* 3. Make next of new Node as head */
new_node.next = head;
/* 4. Move the head to point to new Node */
head = new_node;
}
/* A utilty function that returns true if data is present
in linked list else return false */
public boolean isPresent (int data){
Node t = this.head;
while (t != null)
{
if (t.data == data)
return true;
t = t.next;
}
return false;
}
}
Intersection.java
//Implements the intersection method.
class Intersection{
static public ObjectList intersect(ObjectList list1, ObjectList list2){
ObjectList result = new ObjectList();
//Node t1 = head1;
Node t1 = list1.head;
Node t2 = list2.head;
// Traverse list1 and search each element of it in list2.
// If the element is present in list 2, then insert the
// element to result
while (t1 != null){
if (list2.isPresent(t1.data))
result.push(t1.data);
t1 = t1.next;
}
return result;
}
/* Driver program to test above functions */
public static void main(String args[]){
ObjectList llist1 = new ObjectList();
ObjectList llist2 = new ObjectList();
ObjectList unin = new ObjectList();
ObjectList intersecn = new ObjectList();
/*create a linked lits 10->15->5->20 */
llist1.push(20);
llist1.push(4);
llist1.push(15);
llist1.push(10);
/*create a linked lits 8->4->2->10 */
llist2.push(10);
llist2.push(2);
llist2.push(4);
llist2.push(8);
intersecn = intersect(llist1, llist2);
intersecn.printList();
}
}

More Related Content

Similar to Select three methods in the ObjectList class to work through algori.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.pdfmalavshah9013
 
Write a function to merge two doubly linked lists. The input lists ha.pdf
Write a function to merge two doubly linked lists. The input lists ha.pdfWrite a function to merge two doubly linked lists. The input lists ha.pdf
Write a function to merge two doubly linked lists. The input lists ha.pdfinfo706022
 
The MyLinkedList class used in Listing 24.6 is a one-way directional .docx
 The MyLinkedList class used in Listing 24.6 is a one-way directional .docx The MyLinkedList class used in Listing 24.6 is a one-way directional .docx
The MyLinkedList class used in Listing 24.6 is a one-way directional .docxKomlin1
 
Dividing a linked list into two sublists of almost equal sizesa. A.pdf
Dividing a linked list into two sublists of almost equal sizesa. A.pdfDividing a linked list into two sublists of almost equal sizesa. A.pdf
Dividing a linked list into two sublists of almost equal sizesa. A.pdftesmondday29076
 
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.pdfHi,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.pdfannaelctronics
 
please i need help Im writing a program to test the merge sort alg.pdf
please i need help Im writing a program to test the merge sort alg.pdfplease i need help Im writing a program to test the merge sort alg.pdf
please i need help Im writing a program to test the merge sort alg.pdfezonesolutions
 
Java AssignmentUsing the ListNode.java file below Write method.pdf
Java AssignmentUsing the ListNode.java file below Write method.pdfJava AssignmentUsing the ListNode.java file below Write method.pdf
Java AssignmentUsing the ListNode.java file below Write method.pdfambersushil
 
Sorted number list implementation with linked listsStep 1 Inspec.pdf
 Sorted number list implementation with linked listsStep 1 Inspec.pdf Sorted number list implementation with linked listsStep 1 Inspec.pdf
Sorted number list implementation with linked listsStep 1 Inspec.pdfalmaniaeyewear
 
Note- Can someone help me with the private E get(int index- int curren (1).docx
Note- Can someone help me with the private E get(int index- int curren (1).docxNote- Can someone help me with the private E get(int index- int curren (1).docx
Note- Can someone help me with the private E get(int index- int curren (1).docxVictorzH8Bondx
 
Lab02kdfshdfgajhdfgajhdfgajhdfgjhadgfasjhdgfjhasdgfjh.pdf
Lab02kdfshdfgajhdfgajhdfgajhdfgjhadgfasjhdgfjhasdgfjh.pdfLab02kdfshdfgajhdfgajhdfgajhdfgjhadgfasjhdgfjhasdgfjh.pdf
Lab02kdfshdfgajhdfgajhdfgajhdfgjhadgfasjhdgfjhasdgfjh.pdfQalandarBux2
 
C++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdf
C++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdfC++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdf
C++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdfcallawaycorb73779
 
Note- Can someone help me with the Public boolean add(E value) method.pdf
Note- Can someone help me with the Public boolean add(E value) method.pdfNote- Can someone help me with the Public boolean add(E value) method.pdf
Note- Can someone help me with the Public boolean add(E value) method.pdfStewart29UReesa
 
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
 
In this lab we will write code for working with a Linked List. Node .pdf
In this lab we will write code for working with a Linked List.  Node .pdfIn this lab we will write code for working with a Linked List.  Node .pdf
In this lab we will write code for working with a Linked List. Node .pdffms12345
 
Implement the interface you wrote for Lab B (EntryWayListInterface)..pdf
Implement the interface you wrote for Lab B (EntryWayListInterface)..pdfImplement the interface you wrote for Lab B (EntryWayListInterface)..pdf
Implement the interface you wrote for Lab B (EntryWayListInterface)..pdfrishabjain5053
 

Similar to Select three methods in the ObjectList class to work through algori.pdf (20)

Adt of lists
Adt of listsAdt of lists
Adt of lists
 
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
 
Write a function to merge two doubly linked lists. The input lists ha.pdf
Write a function to merge two doubly linked lists. The input lists ha.pdfWrite a function to merge two doubly linked lists. The input lists ha.pdf
Write a function to merge two doubly linked lists. The input lists ha.pdf
 
The MyLinkedList class used in Listing 24.6 is a one-way directional .docx
 The MyLinkedList class used in Listing 24.6 is a one-way directional .docx The MyLinkedList class used in Listing 24.6 is a one-way directional .docx
The MyLinkedList class used in Listing 24.6 is a one-way directional .docx
 
Dividing a linked list into two sublists of almost equal sizesa. A.pdf
Dividing a linked list into two sublists of almost equal sizesa. A.pdfDividing a linked list into two sublists of almost equal sizesa. A.pdf
Dividing a linked list into two sublists of almost equal sizesa. A.pdf
 
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.pdfHi,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
 
please i need help Im writing a program to test the merge sort alg.pdf
please i need help Im writing a program to test the merge sort alg.pdfplease i need help Im writing a program to test the merge sort alg.pdf
please i need help Im writing a program to test the merge sort alg.pdf
 
Java AssignmentUsing the ListNode.java file below Write method.pdf
Java AssignmentUsing the ListNode.java file below Write method.pdfJava AssignmentUsing the ListNode.java file below Write method.pdf
Java AssignmentUsing the ListNode.java file below Write method.pdf
 
Linked list
Linked list Linked list
Linked list
 
Sorted number list implementation with linked listsStep 1 Inspec.pdf
 Sorted number list implementation with linked listsStep 1 Inspec.pdf Sorted number list implementation with linked listsStep 1 Inspec.pdf
Sorted number list implementation with linked listsStep 1 Inspec.pdf
 
Note- Can someone help me with the private E get(int index- int curren (1).docx
Note- Can someone help me with the private E get(int index- int curren (1).docxNote- Can someone help me with the private E get(int index- int curren (1).docx
Note- Can someone help me with the private E get(int index- int curren (1).docx
 
Lab02kdfshdfgajhdfgajhdfgajhdfgjhadgfasjhdgfjhasdgfjh.pdf
Lab02kdfshdfgajhdfgajhdfgajhdfgjhadgfasjhdgfjhasdgfjh.pdfLab02kdfshdfgajhdfgajhdfgajhdfgjhadgfasjhdgfjhasdgfjh.pdf
Lab02kdfshdfgajhdfgajhdfgajhdfgjhadgfasjhdgfjhasdgfjh.pdf
 
List
ListList
List
 
C++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdf
C++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdfC++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdf
C++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdf
 
Note- Can someone help me with the Public boolean add(E value) method.pdf
Note- Can someone help me with the Public boolean add(E value) method.pdfNote- Can someone help me with the Public boolean add(E value) method.pdf
Note- Can someone help me with the Public boolean add(E value) method.pdf
 
Data Structures in C++I am really new to C++, so links are really .pdf
Data Structures in C++I am really new to C++, so links are really .pdfData Structures in C++I am really new to C++, so links are really .pdf
Data Structures in C++I am really new to C++, so links are really .pdf
 
In this lab we will write code for working with a Linked List. Node .pdf
In this lab we will write code for working with a Linked List.  Node .pdfIn this lab we will write code for working with a Linked List.  Node .pdf
In this lab we will write code for working with a Linked List. Node .pdf
 
Implement the interface you wrote for Lab B (EntryWayListInterface)..pdf
Implement the interface you wrote for Lab B (EntryWayListInterface)..pdfImplement the interface you wrote for Lab B (EntryWayListInterface)..pdf
Implement the interface you wrote for Lab B (EntryWayListInterface)..pdf
 
Linked list
Linked listLinked list
Linked list
 
Unit II Data Structure 2hr topic - List - Operations.pptx
Unit II  Data Structure 2hr topic - List - Operations.pptxUnit II  Data Structure 2hr topic - List - Operations.pptx
Unit II Data Structure 2hr topic - List - Operations.pptx
 

More from aroraopticals15

For a given H0 and level of significance, if you reject the H0 for a.pdf
For a given H0 and level of significance, if you reject the H0 for a.pdfFor a given H0 and level of significance, if you reject the H0 for a.pdf
For a given H0 and level of significance, if you reject the H0 for a.pdfaroraopticals15
 
Find all elements of our ring R that have norm 1. Show that no elemen.pdf
Find all elements of our ring R that have norm 1. Show that no elemen.pdfFind all elements of our ring R that have norm 1. Show that no elemen.pdf
Find all elements of our ring R that have norm 1. Show that no elemen.pdfaroraopticals15
 
Evaluate the decision to have a computer usage policy and the potent.pdf
Evaluate the decision to have a computer usage policy and the potent.pdfEvaluate the decision to have a computer usage policy and the potent.pdf
Evaluate the decision to have a computer usage policy and the potent.pdfaroraopticals15
 
(java) eclipse PleaseDevelop an application that implements a pro.pdf
(java) eclipse PleaseDevelop an application that implements a pro.pdf(java) eclipse PleaseDevelop an application that implements a pro.pdf
(java) eclipse PleaseDevelop an application that implements a pro.pdfaroraopticals15
 
At a sudden contraction in a pipe the diameter changes from D_1 to D_.pdf
At a sudden contraction in a pipe the diameter changes from D_1 to D_.pdfAt a sudden contraction in a pipe the diameter changes from D_1 to D_.pdf
At a sudden contraction in a pipe the diameter changes from D_1 to D_.pdfaroraopticals15
 
Above is a trace depicting mechanical activity of frog heart. A stud.pdf
Above is a trace depicting mechanical activity of frog heart. A stud.pdfAbove is a trace depicting mechanical activity of frog heart. A stud.pdf
Above is a trace depicting mechanical activity of frog heart. A stud.pdfaroraopticals15
 
A gymnosperm, such as Juniperus virginiana, that produces female con.pdf
A gymnosperm, such as Juniperus virginiana, that produces female con.pdfA gymnosperm, such as Juniperus virginiana, that produces female con.pdf
A gymnosperm, such as Juniperus virginiana, that produces female con.pdfaroraopticals15
 
Write short descriptive answer to the following questions Discuss wh.pdf
Write short descriptive answer to the following questions  Discuss wh.pdfWrite short descriptive answer to the following questions  Discuss wh.pdf
Write short descriptive answer to the following questions Discuss wh.pdfaroraopticals15
 
Why should anyone else care about what I do with my sewage on my own .pdf
Why should anyone else care about what I do with my sewage on my own .pdfWhy should anyone else care about what I do with my sewage on my own .pdf
Why should anyone else care about what I do with my sewage on my own .pdfaroraopticals15
 
Why do viral particles, zymosan on fungi, endotoxin (LPS) from gram .pdf
Why do viral particles, zymosan on fungi, endotoxin (LPS) from gram .pdfWhy do viral particles, zymosan on fungi, endotoxin (LPS) from gram .pdf
Why do viral particles, zymosan on fungi, endotoxin (LPS) from gram .pdfaroraopticals15
 
Which of the following used historicalcomparative methods in their .pdf
Which of the following used historicalcomparative methods in their .pdfWhich of the following used historicalcomparative methods in their .pdf
Which of the following used historicalcomparative methods in their .pdfaroraopticals15
 
Which of following is not a class of the phylum platyhelminthes Tre.pdf
Which of following is not a class of the phylum platyhelminthes  Tre.pdfWhich of following is not a class of the phylum platyhelminthes  Tre.pdf
Which of following is not a class of the phylum platyhelminthes Tre.pdfaroraopticals15
 
What is wrong with this code Please fix.code#include stdio.h.pdf
What is wrong with this code Please fix.code#include stdio.h.pdfWhat is wrong with this code Please fix.code#include stdio.h.pdf
What is wrong with this code Please fix.code#include stdio.h.pdfaroraopticals15
 
What are two ways that meiosis could produce gametes that contai.pdf
What are two ways that meiosis could produce gametes that contai.pdfWhat are two ways that meiosis could produce gametes that contai.pdf
What are two ways that meiosis could produce gametes that contai.pdfaroraopticals15
 
what is the process in society that made this change to advertising .pdf
what is the process in society that made this change to advertising .pdfwhat is the process in society that made this change to advertising .pdf
what is the process in society that made this change to advertising .pdfaroraopticals15
 
What is the best way to go about designing an Android AppSoluti.pdf
What is the best way to go about designing an Android AppSoluti.pdfWhat is the best way to go about designing an Android AppSoluti.pdf
What is the best way to go about designing an Android AppSoluti.pdfaroraopticals15
 
Use the following word bank to complete the numbers 51-100. Acoeloma.pdf
Use the following word bank to complete the numbers 51-100.  Acoeloma.pdfUse the following word bank to complete the numbers 51-100.  Acoeloma.pdf
Use the following word bank to complete the numbers 51-100. Acoeloma.pdfaroraopticals15
 
Two cards are randomly selected from a 52-card deck. What is the pro.pdf
Two cards are randomly selected from a 52-card deck. What is the pro.pdfTwo cards are randomly selected from a 52-card deck. What is the pro.pdf
Two cards are randomly selected from a 52-card deck. What is the pro.pdfaroraopticals15
 
Two labs are being compared to determine if they are providing the sa.pdf
Two labs are being compared to determine if they are providing the sa.pdfTwo labs are being compared to determine if they are providing the sa.pdf
Two labs are being compared to determine if they are providing the sa.pdfaroraopticals15
 
Todopackage hwk6; This class contains the configuration of a t.pdf
Todopackage hwk6; This class contains the configuration of a t.pdfTodopackage hwk6; This class contains the configuration of a t.pdf
Todopackage hwk6; This class contains the configuration of a t.pdfaroraopticals15
 

More from aroraopticals15 (20)

For a given H0 and level of significance, if you reject the H0 for a.pdf
For a given H0 and level of significance, if you reject the H0 for a.pdfFor a given H0 and level of significance, if you reject the H0 for a.pdf
For a given H0 and level of significance, if you reject the H0 for a.pdf
 
Find all elements of our ring R that have norm 1. Show that no elemen.pdf
Find all elements of our ring R that have norm 1. Show that no elemen.pdfFind all elements of our ring R that have norm 1. Show that no elemen.pdf
Find all elements of our ring R that have norm 1. Show that no elemen.pdf
 
Evaluate the decision to have a computer usage policy and the potent.pdf
Evaluate the decision to have a computer usage policy and the potent.pdfEvaluate the decision to have a computer usage policy and the potent.pdf
Evaluate the decision to have a computer usage policy and the potent.pdf
 
(java) eclipse PleaseDevelop an application that implements a pro.pdf
(java) eclipse PleaseDevelop an application that implements a pro.pdf(java) eclipse PleaseDevelop an application that implements a pro.pdf
(java) eclipse PleaseDevelop an application that implements a pro.pdf
 
At a sudden contraction in a pipe the diameter changes from D_1 to D_.pdf
At a sudden contraction in a pipe the diameter changes from D_1 to D_.pdfAt a sudden contraction in a pipe the diameter changes from D_1 to D_.pdf
At a sudden contraction in a pipe the diameter changes from D_1 to D_.pdf
 
Above is a trace depicting mechanical activity of frog heart. A stud.pdf
Above is a trace depicting mechanical activity of frog heart. A stud.pdfAbove is a trace depicting mechanical activity of frog heart. A stud.pdf
Above is a trace depicting mechanical activity of frog heart. A stud.pdf
 
A gymnosperm, such as Juniperus virginiana, that produces female con.pdf
A gymnosperm, such as Juniperus virginiana, that produces female con.pdfA gymnosperm, such as Juniperus virginiana, that produces female con.pdf
A gymnosperm, such as Juniperus virginiana, that produces female con.pdf
 
Write short descriptive answer to the following questions Discuss wh.pdf
Write short descriptive answer to the following questions  Discuss wh.pdfWrite short descriptive answer to the following questions  Discuss wh.pdf
Write short descriptive answer to the following questions Discuss wh.pdf
 
Why should anyone else care about what I do with my sewage on my own .pdf
Why should anyone else care about what I do with my sewage on my own .pdfWhy should anyone else care about what I do with my sewage on my own .pdf
Why should anyone else care about what I do with my sewage on my own .pdf
 
Why do viral particles, zymosan on fungi, endotoxin (LPS) from gram .pdf
Why do viral particles, zymosan on fungi, endotoxin (LPS) from gram .pdfWhy do viral particles, zymosan on fungi, endotoxin (LPS) from gram .pdf
Why do viral particles, zymosan on fungi, endotoxin (LPS) from gram .pdf
 
Which of the following used historicalcomparative methods in their .pdf
Which of the following used historicalcomparative methods in their .pdfWhich of the following used historicalcomparative methods in their .pdf
Which of the following used historicalcomparative methods in their .pdf
 
Which of following is not a class of the phylum platyhelminthes Tre.pdf
Which of following is not a class of the phylum platyhelminthes  Tre.pdfWhich of following is not a class of the phylum platyhelminthes  Tre.pdf
Which of following is not a class of the phylum platyhelminthes Tre.pdf
 
What is wrong with this code Please fix.code#include stdio.h.pdf
What is wrong with this code Please fix.code#include stdio.h.pdfWhat is wrong with this code Please fix.code#include stdio.h.pdf
What is wrong with this code Please fix.code#include stdio.h.pdf
 
What are two ways that meiosis could produce gametes that contai.pdf
What are two ways that meiosis could produce gametes that contai.pdfWhat are two ways that meiosis could produce gametes that contai.pdf
What are two ways that meiosis could produce gametes that contai.pdf
 
what is the process in society that made this change to advertising .pdf
what is the process in society that made this change to advertising .pdfwhat is the process in society that made this change to advertising .pdf
what is the process in society that made this change to advertising .pdf
 
What is the best way to go about designing an Android AppSoluti.pdf
What is the best way to go about designing an Android AppSoluti.pdfWhat is the best way to go about designing an Android AppSoluti.pdf
What is the best way to go about designing an Android AppSoluti.pdf
 
Use the following word bank to complete the numbers 51-100. Acoeloma.pdf
Use the following word bank to complete the numbers 51-100.  Acoeloma.pdfUse the following word bank to complete the numbers 51-100.  Acoeloma.pdf
Use the following word bank to complete the numbers 51-100. Acoeloma.pdf
 
Two cards are randomly selected from a 52-card deck. What is the pro.pdf
Two cards are randomly selected from a 52-card deck. What is the pro.pdfTwo cards are randomly selected from a 52-card deck. What is the pro.pdf
Two cards are randomly selected from a 52-card deck. What is the pro.pdf
 
Two labs are being compared to determine if they are providing the sa.pdf
Two labs are being compared to determine if they are providing the sa.pdfTwo labs are being compared to determine if they are providing the sa.pdf
Two labs are being compared to determine if they are providing the sa.pdf
 
Todopackage hwk6; This class contains the configuration of a t.pdf
Todopackage hwk6; This class contains the configuration of a t.pdfTodopackage hwk6; This class contains the configuration of a t.pdf
Todopackage hwk6; This class contains the configuration of a t.pdf
 

Recently uploaded

The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
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.pdfDr Vijay Vishwakarma
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentationcamerronhm
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxJisc
 
How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17Celine George
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxCeline George
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxannathomasp01
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Pooja Bhuva
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...Nguyen Thanh Tu Collection
 
AIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptAIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptNishitharanjan Rout
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSAnaAcapella
 
Simple, Complex, and Compound Sentences Exercises.pdf
Simple, Complex, and Compound Sentences Exercises.pdfSimple, Complex, and Compound Sentences Exercises.pdf
Simple, Complex, and Compound Sentences Exercises.pdfstareducators107
 
Philosophy of china and it's charactistics
Philosophy of china and it's charactisticsPhilosophy of china and it's charactistics
Philosophy of china and it's charactisticshameyhk98
 
21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptxJoelynRubio1
 
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 17Celine George
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structuredhanjurrannsibayan2
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17Celine George
 

Recently uploaded (20)

The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.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
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
AIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptAIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.ppt
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
 
Simple, Complex, and Compound Sentences Exercises.pdf
Simple, Complex, and Compound Sentences Exercises.pdfSimple, Complex, and Compound Sentences Exercises.pdf
Simple, Complex, and Compound Sentences Exercises.pdf
 
Philosophy of china and it's charactistics
Philosophy of china and it's charactisticsPhilosophy of china and it's charactistics
Philosophy of china and it's charactistics
 
21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx
 
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
 
Call Girls in Uttam Nagar (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in  Uttam Nagar (delhi) call me [🔝9953056974🔝] escort service 24X7Call Girls in  Uttam Nagar (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in Uttam Nagar (delhi) call me [🔝9953056974🔝] escort service 24X7
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 

Select three methods in the ObjectList class to work through algori.pdf

  • 1. Select three methods in the ObjectList class to work through algorithmically. Describe any special cases or boundary conditions that might exist for each of the three methods selected. Be sure to draw pictures as you work through the methods. Remember that you cannot work on linked lists without drawing pictures. The homework will not be accepted without submitting the pictures! Write a Java method with the signature: public objectList intersect (objectList list1, objectList list2) that accepts two unordered linear linked lists and returns a third linear linked list whose nodes contains the intersection of the two original linear linked lists. Note that the intersection of two lists is a new list containing the elements that the two lists have in common, without modifying the two original lists. Describe any boundary conditions that might exist. Solution Node.java //Defines each node of a linked list public class Node{ int data; Node next; Node(int d) { data = d; next = null; } } ObjectList.java public class ObjectList{ public Node head; /* Utility function to print list */ public void printList() { Node temp = head; while(temp != null) { System.out.print(temp.data+" "); temp = temp.next; } System.out.println();
  • 2. } /* Inserts a node at start of linked list */ public void push(int new_data) { /* 1 & 2: Allocate the Node & Put in the data*/ Node new_node = new Node(new_data); /* 3. Make next of new Node as head */ new_node.next = head; /* 4. Move the head to point to new Node */ head = new_node; } /* A utilty function that returns true if data is present in linked list else return false */ public boolean isPresent (int data){ Node t = this.head; while (t != null) { if (t.data == data) return true; t = t.next; } return false; } } Intersection.java //Implements the intersection method. class Intersection{ static public ObjectList intersect(ObjectList list1, ObjectList list2){ ObjectList result = new ObjectList(); //Node t1 = head1; Node t1 = list1.head; Node t2 = list2.head; // Traverse list1 and search each element of it in list2.
  • 3. // If the element is present in list 2, then insert the // element to result while (t1 != null){ if (list2.isPresent(t1.data)) result.push(t1.data); t1 = t1.next; } return result; } /* Driver program to test above functions */ public static void main(String args[]){ ObjectList llist1 = new ObjectList(); ObjectList llist2 = new ObjectList(); ObjectList unin = new ObjectList(); ObjectList intersecn = new ObjectList(); /*create a linked lits 10->15->5->20 */ llist1.push(20); llist1.push(4); llist1.push(15); llist1.push(10); /*create a linked lits 8->4->2->10 */ llist2.push(10); llist2.push(2); llist2.push(4); llist2.push(8); intersecn = intersect(llist1, llist2); intersecn.printList(); } }