SlideShare a Scribd company logo
1 of 12
Download to read offline
Problem 1: Create Node class (or use what you have done in Lab4)
• Add methods to get and set, Data and Link
• Here the data is an object. (java object) your Linked List can hold any java class.
a) Create MyLinkedList2 class and write methods to
• Methods to insert nodes at the beginning, at the end and at a specific position. insertFirst(Node
x), insertLast(Node x) , insertLast(Node x, int pos)
• Methods to delete node from the beginning and from the end. delFirst(), delLast()
• Method to search the Linked List for a specific object. searchList(x Object)
• Method to Sort the Linked List in ascendant or descendant order according to the object
value(s). for example sorted by name, by age, by gpa. sortAsc(),sortDesc().
• Method to display all nodes objects (printing an object is related to its toString() method).
• Method to return the largest and smallest object in the list – maxList(), minList() according to
some specific object members.
. • Method to return the number of nodes – listSize()
• Method to merge two linked Lists into one. MyLinkedList2 list3= mergeList(MyLinkedList2
list1, MyLinkedList2 list2)
b) Create Main class : MyLinkedList2Demo
• Create a linked List LL1 and insert some objects to it. Use any a student java class.
• Fill LL1 by adding students from an input file.
• Display all the objects (students) in the List LL1
• Search for a particular object (Student by name or by Id or both) in LL1 and print true or false
• Sort LL1 and display it ( using asc and desc on multiple members)
• Perform all the delete methods on LL1.
• Perform all the insert methods on LL1.
• Call and run all the implemented methods in a sequential order. NB: Organize a nice output for
all the questions above.
Problem 2: Same as Pb1 using double linked lists. Create Nod3e and MyLinkedList3 classes.
--------------------------------------------------------------------------------------------------------------------
---------------------------------------------------
The input file :
id fname lname age gpa year college cuCourses totalCourses
201412345 Amna chamisi 17 2.1 2014 CIT 5 30
201112345 Amna chamisi 17 2.1 2014 ENG 31 32
201412345 Amna chamisi 17 2.1 2014 COE 5 29
201412345 Amna chamisi 17 2.1 2014 CIT 5 30
201412345 Amna chamisi 17 2.1 2014 CIT 5 30
201412345 Amna chamisi 17 2.1 2014 CIT 5 30
201412345 Amna chamisi 17 2.1 2014 CIT 5 30
Solution
/**
* Node.java
* @author
*
*/
public class Node {
public Object getObj() {
return obj;
}
public Node setObj(Object obj) {
this.obj = obj;
return this;
}
public Node getNext() {
return next;
}
public Node setNext(Node next) {
this.next = next;
return this;
}
private Object obj;
private Node next;
}
import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedList;
/**
* MyLinkedList2.java
* @author
*
*/
public class MyLinkedList2 {
public void insertFirst(Node x) {
if (head == null) {
head = x;
} else {
x.setNext(head);
}
}
public void insertLast(Node x) {
if (head == null) {
head = x;
return;
} else {
Node temp = head;
while (temp.getNext() != null) {
temp = temp.getNext();
}
temp.setNext(x);
}
}
public void insertPos(Node x, int pos) {
// starting with 0
if (pos < 0)
return;
if (head == null) {
if (pos > 0)
return;
head = x;
return;
}
if (pos == 0) {
insertFirst(x);
return;
}
Node temp = head;
for (int i = 1; i < pos; i++) {
temp = temp.getNext();
}
x.setNext(temp.getNext());
temp.setNext(x);
}
public void delFirst() {
if (head == null)
return;
head = head.getNext();
}
public void delLast() {
Node temp = head;
if (head != null) {
if (head.getNext() == null) {
head = null;
return;
}
while (temp.getNext().getNext() != null) {
temp = temp.getNext();
}
temp.setNext(null);
}
}
public boolean search(Object x, Comparator c) {
if (head == null)
return false;
Node temp = head;
while (temp.getNext() != null) {
if (c.compare(x, temp.getObj()) == 0) {
return true;
}
temp = temp.getNext();
}
return false;
}
public void sortAsc(Comparator c) {
if (head == null)
return;
LinkedList ll = new LinkedList<>();
Node temp = head;
while (temp.getNext() != null) {
ll.add(temp.getObj());
temp = temp.getNext();
}
Collections.sort(ll, c);
head=new Node().setObj((Student) ll.get(0));
Node t = head;
for (int i = 1; i < ll.size(); i++) {
t.setNext(new Node().setObj((Student)ll.get(i)));
t = t.getNext();
}
}
public void sortDesc(Comparator c) {
if (head == null)
return;
LinkedList ll = new LinkedList<>();
Node temp = head;
while (temp.getNext() != null) {
ll.add(temp.getObj());
temp = temp.getNext();
}
Collections.sort(ll, c);
head=new Node().setObj((Student) ll.get(0));
Node t = head;
for (int i = 1; i < ll.size(); i++) {
t.setNext(new Node().setObj((Student)ll.get(i)));
t = t.getNext();
}
}
public void printAll() {
if(head==null)
return;
Node temp=head;
while(temp.getNext()!=null)
{
System.out.println(temp.getObj());
temp=temp.getNext();
}
}
public Object maxList(Comparator c) {
if(head==null)return null;
Node max=head;
Node temp=head;
while(temp.getNext()!=null)
{
if(c.compare(max, temp)<0)
max=temp;
temp=temp.getNext();
}
return max;
}
public Object minList(Comparator c) {
if(head==null)return null;
Node min=head;
Node temp=head;
while(temp.getNext()!=null)
{
if(c.compare(min, temp)>0)
min=temp;
temp=temp.getNext();
}
return min;
}
public int listSize() {
if(head==null)
return 0;
int i=0;
Node temp=head;
while(temp.getNext()!=null)
{
i++;
temp=temp.getNext();
}
return i;
}
public static MyLinkedList2 mergeList(MyLinkedList2 list1, MyLinkedList2 list2) {
Node temp=list1.head;
if(temp==null) return list2;
Node temp1=temp;
while(temp1.getNext()!=null)
{
temp1=temp1.getNext();
}
temp1.setNext(list2.head);
return list1;
}
private Node head;
}
import java.util.Comparator;
import java.util.Scanner;
/**
* MyLinkList2Demo.java
*
* @author
*
*/
public class MyLinkList2Demo {
public static void main(String[] args) {
MyLinkedList2 ll1 = new MyLinkedList2();
Scanner sc = new Scanner(System.in);
Student st = null;
int l = 0;
while (l < 4) {
l++;
Student student = new Student(sc.nextInt(), sc.next(), sc.next(), sc.nextInt(),
sc.nextDouble(),
sc.nextInt(), sc.next(), sc.nextInt(), sc.nextInt());
st = student;
ll1.insertLast(new Node().setObj(student)); // inserting into linked
// list
}
sc.close();
ll1.printAll();
ll1.search(st, new Comparator() {
@Override
public int compare(Object o1, Object o2) {
Student s1 = (Student) o1;
Student s2 = (Student) o2;
if (s1.getAge() < s2.getAge()) // if you want search based on
// different parameter just
// change here
{
return -1;
} else if (s1.getAge() == s2.getAge()) {
return 0;
}
return 1;
}
});
ll1.sortAsc(new Comparator() {
@Override
public int compare(Object o1, Object o2) {
Student s1 = (Student) o1;
Student s2 = (Student) o2;
if (s1.getAge() < s2.getAge()) // if you want sort based on
// different parameter just
// change here
{
return -1; // read about compare method
} else if (s1.getAge() == s2.getAge()) {
return 0;
}
return 1;
}
});
ll1.sortDesc(new Comparator() {
@Override
public int compare(Object o1, Object o2) {
Student s1 = (Student) o1;
Student s2 = (Student) o2;
if (s1.getAge() < s2.getAge()) // if you want sort based on
// different parameter just
// change here
{
return 1; // read about compare method
} else if (s1.getAge() == s2.getAge()) {
return 0;
}
return -1;
}
});
}
}
/**
* Student.java
* @author
*
*/
public class Student {
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getFname() {
return fname;
}
public void setFname(String fname) {
this.fname = fname;
}
public String getLname() {
return lname;
}
public void setLname(String lname) {
this.lname = lname;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public double getGpa() {
return gpa;
}
public void setGpa(double gpa) {
this.gpa = gpa;
}
public int getYear() {
return year;
}
public void setYear(int year) {
this.year = year;
}
public String getCollege() {
return college;
}
public void setCollege(String college) {
this.college = college;
}
public int getCuCourses() {
return cuCourses;
}
public void setCuCourses(int cuCourses) {
this.cuCourses = cuCourses;
}
public int getTotalCourses() {
return totalCourses;
}
public void setTotalCourses(int totalCourses) {
this.totalCourses = totalCourses;
}
private int id;
private String fname;
private String lname;
private int age;
private double gpa;
private int year;
private String college;
private int cuCourses;
private int totalCourses;
public Student(int id, String fname, String lname, int age, double gpa, int year, String college,
int cuCourses,
int totalCourses) {
super();
this.id = id;
this.fname = fname;
this.lname = lname;
this.age = age;
this.gpa = gpa;
this.year = year;
this.college = college;
this.cuCourses = cuCourses;
this.totalCourses = totalCourses;
}
@Override
public String toString() {
return "Student [id=" + id + ", fname=" + fname + ", lname=" + lname + ", age=" + age
+ ", gpa=" + gpa
+ ", year=" + year + ", college=" + college + ", cuCourses=" + cuCourses + ",
totalCourses="
+ totalCourses + "] ";
}
}

More Related Content

Similar to Problem 1 Create Node class (or use what you have done in Lab4)• .pdf

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.pdfFor each task, submit your source java code file.(1) Objective Im.pdf
For each task, submit your source java code file.(1) Objective Im.pdfdhavalbl38
 
Functional Programming You Already Know - Kevlin Henney - Codemotion Rome 2015
Functional Programming You Already Know - Kevlin Henney - Codemotion Rome 2015Functional Programming You Already Know - Kevlin Henney - Codemotion Rome 2015
Functional Programming You Already Know - Kevlin Henney - Codemotion Rome 2015Codemotion
 
Core Java Programming Language (JSE) : Chapter IX - Collections and Generic F...
Core Java Programming Language (JSE) : Chapter IX - Collections and Generic F...Core Java Programming Language (JSE) : Chapter IX - Collections and Generic F...
Core Java Programming Language (JSE) : Chapter IX - Collections and Generic F...WebStackAcademy
 
Data Structure Using C
Data Structure Using CData Structure Using C
Data Structure Using Ccpjcollege
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data StructureZidny Nafan
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data StructureSriram Raj
 
File LinkedList.java Defines a doubly-l.pdf
File LinkedList.java Defines a doubly-l.pdfFile LinkedList.java Defines a doubly-l.pdf
File LinkedList.java Defines a doubly-l.pdfConint29
 
coding in C- Create a function called reverseList that takes the head.docx
coding in C- Create a function called reverseList that takes the head.docxcoding in C- Create a function called reverseList that takes the head.docx
coding in C- Create a function called reverseList that takes the head.docxtienlivick
 
Write the Java source code necessary to build a solution for the pro.pdf
Write the Java source code necessary to build a solution for the pro.pdfWrite the Java source code necessary to build a solution for the pro.pdf
Write the Java source code necessary to build a solution for the pro.pdffckindswear
 

Similar to Problem 1 Create Node class (or use what you have done in Lab4)• .pdf (20)

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.pdfFor 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
 
Functional Programming You Already Know - Kevlin Henney - Codemotion Rome 2015
Functional Programming You Already Know - Kevlin Henney - Codemotion Rome 2015Functional Programming You Already Know - Kevlin Henney - Codemotion Rome 2015
Functional Programming You Already Know - Kevlin Henney - Codemotion Rome 2015
 
Unit7 C
Unit7 CUnit7 C
Unit7 C
 
Core Java Programming Language (JSE) : Chapter IX - Collections and Generic F...
Core Java Programming Language (JSE) : Chapter IX - Collections and Generic F...Core Java Programming Language (JSE) : Chapter IX - Collections and Generic F...
Core Java Programming Language (JSE) : Chapter IX - Collections and Generic F...
 
Data structure
Data  structureData  structure
Data structure
 
L03 Software Design
L03 Software DesignL03 Software Design
L03 Software Design
 
Data Structure Using C
Data Structure Using CData Structure Using C
Data Structure Using C
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data Structure
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data Structure
 
File LinkedList.java Defines a doubly-l.pdf
File LinkedList.java Defines a doubly-l.pdfFile LinkedList.java Defines a doubly-l.pdf
File LinkedList.java Defines a doubly-l.pdf
 
16-sorting.ppt
16-sorting.ppt16-sorting.ppt
16-sorting.ppt
 
Lecture3.pdf
Lecture3.pdfLecture3.pdf
Lecture3.pdf
 
Jeop game-final-review
Jeop game-final-reviewJeop game-final-review
Jeop game-final-review
 
iOS Session-2
iOS Session-2iOS Session-2
iOS Session-2
 
Functional object
Functional objectFunctional object
Functional object
 
Lab-2.4 101.pdf
Lab-2.4 101.pdfLab-2.4 101.pdf
Lab-2.4 101.pdf
 
coding in C- Create a function called reverseList that takes the head.docx
coding in C- Create a function called reverseList that takes the head.docxcoding in C- Create a function called reverseList that takes the head.docx
coding in C- Create a function called reverseList that takes the head.docx
 
Write the Java source code necessary to build a solution for the pro.pdf
Write the Java source code necessary to build a solution for the pro.pdfWrite the Java source code necessary to build a solution for the pro.pdf
Write the Java source code necessary to build a solution for the pro.pdf
 
Linked list
Linked list Linked list
Linked list
 
05-stack_queue.ppt
05-stack_queue.ppt05-stack_queue.ppt
05-stack_queue.ppt
 

More from mumnesh

Poisson distribution] The number of data packets arriving in 1 sec at.pdf
Poisson distribution] The number of data packets arriving in 1 sec at.pdfPoisson distribution] The number of data packets arriving in 1 sec at.pdf
Poisson distribution] The number of data packets arriving in 1 sec at.pdfmumnesh
 
One of your friends has several brothers and sisters, each quite dif.pdf
One of your friends has several brothers and sisters, each quite dif.pdfOne of your friends has several brothers and sisters, each quite dif.pdf
One of your friends has several brothers and sisters, each quite dif.pdfmumnesh
 
Malpighiaceae luonanthaceae Ochnaceae Flacourtiaceae O Monilophytes G.pdf
Malpighiaceae luonanthaceae Ochnaceae Flacourtiaceae O Monilophytes G.pdfMalpighiaceae luonanthaceae Ochnaceae Flacourtiaceae O Monilophytes G.pdf
Malpighiaceae luonanthaceae Ochnaceae Flacourtiaceae O Monilophytes G.pdfmumnesh
 
In JavaWrite a program that reads a text file that contains a gra.pdf
In JavaWrite a program that reads a text file that contains a gra.pdfIn JavaWrite a program that reads a text file that contains a gra.pdf
In JavaWrite a program that reads a text file that contains a gra.pdfmumnesh
 
How does Pb and TCE partition between components of soil (mineral, o.pdf
How does Pb and TCE partition between components of soil (mineral, o.pdfHow does Pb and TCE partition between components of soil (mineral, o.pdf
How does Pb and TCE partition between components of soil (mineral, o.pdfmumnesh
 
Hi, please I need help with the correct answer to the above multiple.pdf
Hi, please I need help with the correct answer to the above multiple.pdfHi, please I need help with the correct answer to the above multiple.pdf
Hi, please I need help with the correct answer to the above multiple.pdfmumnesh
 
For which phyla are megaspores a shared trait Bryophyta Monilophyt.pdf
For which phyla are megaspores a shared trait  Bryophyta  Monilophyt.pdfFor which phyla are megaspores a shared trait  Bryophyta  Monilophyt.pdf
For which phyla are megaspores a shared trait Bryophyta Monilophyt.pdfmumnesh
 
For Programming Embedded SystemsQ-07 Whcih variable and condition.pdf
For Programming Embedded SystemsQ-07 Whcih variable and condition.pdfFor Programming Embedded SystemsQ-07 Whcih variable and condition.pdf
For Programming Embedded SystemsQ-07 Whcih variable and condition.pdfmumnesh
 
For analysis of Thermodynamic Cycle, we draw T-s or P-h diagram. Why.pdf
For analysis of Thermodynamic Cycle, we draw T-s or P-h diagram. Why.pdfFor analysis of Thermodynamic Cycle, we draw T-s or P-h diagram. Why.pdf
For analysis of Thermodynamic Cycle, we draw T-s or P-h diagram. Why.pdfmumnesh
 
Fill in the blank. A contingency table relates only continuous rando.pdf
Fill in the blank. A contingency table relates  only continuous rando.pdfFill in the blank. A contingency table relates  only continuous rando.pdf
Fill in the blank. A contingency table relates only continuous rando.pdfmumnesh
 
Discuss the dangers associated with hydrogen sulfide in the petro.pdf
Discuss the dangers associated with hydrogen sulfide in the petro.pdfDiscuss the dangers associated with hydrogen sulfide in the petro.pdf
Discuss the dangers associated with hydrogen sulfide in the petro.pdfmumnesh
 
Complete the following paragraph to describe the various reproductive.pdf
Complete the following paragraph to describe the various reproductive.pdfComplete the following paragraph to describe the various reproductive.pdf
Complete the following paragraph to describe the various reproductive.pdfmumnesh
 
CommunicationsSystems have four basic properties (holism, equi-fi.pdf
CommunicationsSystems have four basic properties (holism, equi-fi.pdfCommunicationsSystems have four basic properties (holism, equi-fi.pdf
CommunicationsSystems have four basic properties (holism, equi-fi.pdfmumnesh
 
Based on your reading of the GCU introduction and the textbooks, wha.pdf
Based on your reading of the GCU introduction and the textbooks, wha.pdfBased on your reading of the GCU introduction and the textbooks, wha.pdf
Based on your reading of the GCU introduction and the textbooks, wha.pdfmumnesh
 
Answer using Giardias, Shiga-toxin producing E.coli1.Causative Agn.pdf
Answer using Giardias, Shiga-toxin producing E.coli1.Causative Agn.pdfAnswer using Giardias, Shiga-toxin producing E.coli1.Causative Agn.pdf
Answer using Giardias, Shiga-toxin producing E.coli1.Causative Agn.pdfmumnesh
 
Abraham Shine recently opaned his own accounting fiem on April 1, whi.pdf
Abraham Shine recently opaned his own accounting fiem on April 1, whi.pdfAbraham Shine recently opaned his own accounting fiem on April 1, whi.pdf
Abraham Shine recently opaned his own accounting fiem on April 1, whi.pdfmumnesh
 
29. This figure shows the principal coronary blood vessels. Which one.pdf
29. This figure shows the principal coronary blood vessels. Which one.pdf29. This figure shows the principal coronary blood vessels. Which one.pdf
29. This figure shows the principal coronary blood vessels. Which one.pdfmumnesh
 
14. Suppose I have collected the names of people in several separate.pdf
14. Suppose I have collected the names of people in several separate.pdf14. Suppose I have collected the names of people in several separate.pdf
14. Suppose I have collected the names of people in several separate.pdfmumnesh
 
4. The size of instructions can be fixed or variable. What are advant.pdf
4. The size of instructions can be fixed or variable. What are advant.pdf4. The size of instructions can be fixed or variable. What are advant.pdf
4. The size of instructions can be fixed or variable. What are advant.pdfmumnesh
 
13. What is the difference between post-consumer recycled materials a.pdf
13. What is the difference between post-consumer recycled materials a.pdf13. What is the difference between post-consumer recycled materials a.pdf
13. What is the difference between post-consumer recycled materials a.pdfmumnesh
 

More from mumnesh (20)

Poisson distribution] The number of data packets arriving in 1 sec at.pdf
Poisson distribution] The number of data packets arriving in 1 sec at.pdfPoisson distribution] The number of data packets arriving in 1 sec at.pdf
Poisson distribution] The number of data packets arriving in 1 sec at.pdf
 
One of your friends has several brothers and sisters, each quite dif.pdf
One of your friends has several brothers and sisters, each quite dif.pdfOne of your friends has several brothers and sisters, each quite dif.pdf
One of your friends has several brothers and sisters, each quite dif.pdf
 
Malpighiaceae luonanthaceae Ochnaceae Flacourtiaceae O Monilophytes G.pdf
Malpighiaceae luonanthaceae Ochnaceae Flacourtiaceae O Monilophytes G.pdfMalpighiaceae luonanthaceae Ochnaceae Flacourtiaceae O Monilophytes G.pdf
Malpighiaceae luonanthaceae Ochnaceae Flacourtiaceae O Monilophytes G.pdf
 
In JavaWrite a program that reads a text file that contains a gra.pdf
In JavaWrite a program that reads a text file that contains a gra.pdfIn JavaWrite a program that reads a text file that contains a gra.pdf
In JavaWrite a program that reads a text file that contains a gra.pdf
 
How does Pb and TCE partition between components of soil (mineral, o.pdf
How does Pb and TCE partition between components of soil (mineral, o.pdfHow does Pb and TCE partition between components of soil (mineral, o.pdf
How does Pb and TCE partition between components of soil (mineral, o.pdf
 
Hi, please I need help with the correct answer to the above multiple.pdf
Hi, please I need help with the correct answer to the above multiple.pdfHi, please I need help with the correct answer to the above multiple.pdf
Hi, please I need help with the correct answer to the above multiple.pdf
 
For which phyla are megaspores a shared trait Bryophyta Monilophyt.pdf
For which phyla are megaspores a shared trait  Bryophyta  Monilophyt.pdfFor which phyla are megaspores a shared trait  Bryophyta  Monilophyt.pdf
For which phyla are megaspores a shared trait Bryophyta Monilophyt.pdf
 
For Programming Embedded SystemsQ-07 Whcih variable and condition.pdf
For Programming Embedded SystemsQ-07 Whcih variable and condition.pdfFor Programming Embedded SystemsQ-07 Whcih variable and condition.pdf
For Programming Embedded SystemsQ-07 Whcih variable and condition.pdf
 
For analysis of Thermodynamic Cycle, we draw T-s or P-h diagram. Why.pdf
For analysis of Thermodynamic Cycle, we draw T-s or P-h diagram. Why.pdfFor analysis of Thermodynamic Cycle, we draw T-s or P-h diagram. Why.pdf
For analysis of Thermodynamic Cycle, we draw T-s or P-h diagram. Why.pdf
 
Fill in the blank. A contingency table relates only continuous rando.pdf
Fill in the blank. A contingency table relates  only continuous rando.pdfFill in the blank. A contingency table relates  only continuous rando.pdf
Fill in the blank. A contingency table relates only continuous rando.pdf
 
Discuss the dangers associated with hydrogen sulfide in the petro.pdf
Discuss the dangers associated with hydrogen sulfide in the petro.pdfDiscuss the dangers associated with hydrogen sulfide in the petro.pdf
Discuss the dangers associated with hydrogen sulfide in the petro.pdf
 
Complete the following paragraph to describe the various reproductive.pdf
Complete the following paragraph to describe the various reproductive.pdfComplete the following paragraph to describe the various reproductive.pdf
Complete the following paragraph to describe the various reproductive.pdf
 
CommunicationsSystems have four basic properties (holism, equi-fi.pdf
CommunicationsSystems have four basic properties (holism, equi-fi.pdfCommunicationsSystems have four basic properties (holism, equi-fi.pdf
CommunicationsSystems have four basic properties (holism, equi-fi.pdf
 
Based on your reading of the GCU introduction and the textbooks, wha.pdf
Based on your reading of the GCU introduction and the textbooks, wha.pdfBased on your reading of the GCU introduction and the textbooks, wha.pdf
Based on your reading of the GCU introduction and the textbooks, wha.pdf
 
Answer using Giardias, Shiga-toxin producing E.coli1.Causative Agn.pdf
Answer using Giardias, Shiga-toxin producing E.coli1.Causative Agn.pdfAnswer using Giardias, Shiga-toxin producing E.coli1.Causative Agn.pdf
Answer using Giardias, Shiga-toxin producing E.coli1.Causative Agn.pdf
 
Abraham Shine recently opaned his own accounting fiem on April 1, whi.pdf
Abraham Shine recently opaned his own accounting fiem on April 1, whi.pdfAbraham Shine recently opaned his own accounting fiem on April 1, whi.pdf
Abraham Shine recently opaned his own accounting fiem on April 1, whi.pdf
 
29. This figure shows the principal coronary blood vessels. Which one.pdf
29. This figure shows the principal coronary blood vessels. Which one.pdf29. This figure shows the principal coronary blood vessels. Which one.pdf
29. This figure shows the principal coronary blood vessels. Which one.pdf
 
14. Suppose I have collected the names of people in several separate.pdf
14. Suppose I have collected the names of people in several separate.pdf14. Suppose I have collected the names of people in several separate.pdf
14. Suppose I have collected the names of people in several separate.pdf
 
4. The size of instructions can be fixed or variable. What are advant.pdf
4. The size of instructions can be fixed or variable. What are advant.pdf4. The size of instructions can be fixed or variable. What are advant.pdf
4. The size of instructions can be fixed or variable. What are advant.pdf
 
13. What is the difference between post-consumer recycled materials a.pdf
13. What is the difference between post-consumer recycled materials a.pdf13. What is the difference between post-consumer recycled materials a.pdf
13. What is the difference between post-consumer recycled materials a.pdf
 

Recently uploaded

SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerunnathinaik
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Science lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonScience lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonJericReyAuditor
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 

Recently uploaded (20)

SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developer
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Science lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonScience lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lesson
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 

Problem 1 Create Node class (or use what you have done in Lab4)• .pdf

  • 1. Problem 1: Create Node class (or use what you have done in Lab4) • Add methods to get and set, Data and Link • Here the data is an object. (java object) your Linked List can hold any java class. a) Create MyLinkedList2 class and write methods to • Methods to insert nodes at the beginning, at the end and at a specific position. insertFirst(Node x), insertLast(Node x) , insertLast(Node x, int pos) • Methods to delete node from the beginning and from the end. delFirst(), delLast() • Method to search the Linked List for a specific object. searchList(x Object) • Method to Sort the Linked List in ascendant or descendant order according to the object value(s). for example sorted by name, by age, by gpa. sortAsc(),sortDesc(). • Method to display all nodes objects (printing an object is related to its toString() method). • Method to return the largest and smallest object in the list – maxList(), minList() according to some specific object members. . • Method to return the number of nodes – listSize() • Method to merge two linked Lists into one. MyLinkedList2 list3= mergeList(MyLinkedList2 list1, MyLinkedList2 list2) b) Create Main class : MyLinkedList2Demo • Create a linked List LL1 and insert some objects to it. Use any a student java class. • Fill LL1 by adding students from an input file. • Display all the objects (students) in the List LL1 • Search for a particular object (Student by name or by Id or both) in LL1 and print true or false • Sort LL1 and display it ( using asc and desc on multiple members) • Perform all the delete methods on LL1. • Perform all the insert methods on LL1. • Call and run all the implemented methods in a sequential order. NB: Organize a nice output for all the questions above. Problem 2: Same as Pb1 using double linked lists. Create Nod3e and MyLinkedList3 classes. -------------------------------------------------------------------------------------------------------------------- --------------------------------------------------- The input file : id fname lname age gpa year college cuCourses totalCourses 201412345 Amna chamisi 17 2.1 2014 CIT 5 30 201112345 Amna chamisi 17 2.1 2014 ENG 31 32 201412345 Amna chamisi 17 2.1 2014 COE 5 29 201412345 Amna chamisi 17 2.1 2014 CIT 5 30
  • 2. 201412345 Amna chamisi 17 2.1 2014 CIT 5 30 201412345 Amna chamisi 17 2.1 2014 CIT 5 30 201412345 Amna chamisi 17 2.1 2014 CIT 5 30 Solution /** * Node.java * @author * */ public class Node { public Object getObj() { return obj; } public Node setObj(Object obj) { this.obj = obj; return this; } public Node getNext() { return next; } public Node setNext(Node next) { this.next = next; return this; } private Object obj; private Node next; } import java.util.Collections; import java.util.Comparator; import java.util.LinkedList; /** * MyLinkedList2.java * @author *
  • 3. */ public class MyLinkedList2 { public void insertFirst(Node x) { if (head == null) { head = x; } else { x.setNext(head); } } public void insertLast(Node x) { if (head == null) { head = x; return; } else { Node temp = head; while (temp.getNext() != null) { temp = temp.getNext(); } temp.setNext(x); } } public void insertPos(Node x, int pos) { // starting with 0 if (pos < 0) return; if (head == null) { if (pos > 0) return; head = x; return; } if (pos == 0) { insertFirst(x); return; } Node temp = head;
  • 4. for (int i = 1; i < pos; i++) { temp = temp.getNext(); } x.setNext(temp.getNext()); temp.setNext(x); } public void delFirst() { if (head == null) return; head = head.getNext(); } public void delLast() { Node temp = head; if (head != null) { if (head.getNext() == null) { head = null; return; } while (temp.getNext().getNext() != null) { temp = temp.getNext(); } temp.setNext(null); } } public boolean search(Object x, Comparator c) { if (head == null) return false; Node temp = head; while (temp.getNext() != null) { if (c.compare(x, temp.getObj()) == 0) { return true; } temp = temp.getNext(); } return false; }
  • 5. public void sortAsc(Comparator c) { if (head == null) return; LinkedList ll = new LinkedList<>(); Node temp = head; while (temp.getNext() != null) { ll.add(temp.getObj()); temp = temp.getNext(); } Collections.sort(ll, c); head=new Node().setObj((Student) ll.get(0)); Node t = head; for (int i = 1; i < ll.size(); i++) { t.setNext(new Node().setObj((Student)ll.get(i))); t = t.getNext(); } } public void sortDesc(Comparator c) { if (head == null) return; LinkedList ll = new LinkedList<>(); Node temp = head; while (temp.getNext() != null) { ll.add(temp.getObj()); temp = temp.getNext(); } Collections.sort(ll, c); head=new Node().setObj((Student) ll.get(0)); Node t = head; for (int i = 1; i < ll.size(); i++) { t.setNext(new Node().setObj((Student)ll.get(i))); t = t.getNext(); } }
  • 6. public void printAll() { if(head==null) return; Node temp=head; while(temp.getNext()!=null) { System.out.println(temp.getObj()); temp=temp.getNext(); } } public Object maxList(Comparator c) { if(head==null)return null; Node max=head; Node temp=head; while(temp.getNext()!=null) { if(c.compare(max, temp)<0) max=temp; temp=temp.getNext(); } return max; } public Object minList(Comparator c) { if(head==null)return null; Node min=head; Node temp=head; while(temp.getNext()!=null) { if(c.compare(min, temp)>0) min=temp; temp=temp.getNext(); } return min; } public int listSize() {
  • 7. if(head==null) return 0; int i=0; Node temp=head; while(temp.getNext()!=null) { i++; temp=temp.getNext(); } return i; } public static MyLinkedList2 mergeList(MyLinkedList2 list1, MyLinkedList2 list2) { Node temp=list1.head; if(temp==null) return list2; Node temp1=temp; while(temp1.getNext()!=null) { temp1=temp1.getNext(); } temp1.setNext(list2.head); return list1; } private Node head; } import java.util.Comparator; import java.util.Scanner; /** * MyLinkList2Demo.java * * @author * */ public class MyLinkList2Demo {
  • 8. public static void main(String[] args) { MyLinkedList2 ll1 = new MyLinkedList2(); Scanner sc = new Scanner(System.in); Student st = null; int l = 0; while (l < 4) { l++; Student student = new Student(sc.nextInt(), sc.next(), sc.next(), sc.nextInt(), sc.nextDouble(), sc.nextInt(), sc.next(), sc.nextInt(), sc.nextInt()); st = student; ll1.insertLast(new Node().setObj(student)); // inserting into linked // list } sc.close(); ll1.printAll(); ll1.search(st, new Comparator() { @Override public int compare(Object o1, Object o2) { Student s1 = (Student) o1; Student s2 = (Student) o2; if (s1.getAge() < s2.getAge()) // if you want search based on // different parameter just // change here { return -1; } else if (s1.getAge() == s2.getAge()) { return 0; } return 1; } }); ll1.sortAsc(new Comparator() { @Override public int compare(Object o1, Object o2) { Student s1 = (Student) o1;
  • 9. Student s2 = (Student) o2; if (s1.getAge() < s2.getAge()) // if you want sort based on // different parameter just // change here { return -1; // read about compare method } else if (s1.getAge() == s2.getAge()) { return 0; } return 1; } }); ll1.sortDesc(new Comparator() { @Override public int compare(Object o1, Object o2) { Student s1 = (Student) o1; Student s2 = (Student) o2; if (s1.getAge() < s2.getAge()) // if you want sort based on // different parameter just // change here { return 1; // read about compare method } else if (s1.getAge() == s2.getAge()) { return 0; } return -1; } }); } } /** * Student.java * @author * */ public class Student {
  • 10. public int getId() { return id; } public void setId(int id) { this.id = id; } public String getFname() { return fname; } public void setFname(String fname) { this.fname = fname; } public String getLname() { return lname; } public void setLname(String lname) { this.lname = lname; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } public double getGpa() { return gpa; } public void setGpa(double gpa) { this.gpa = gpa; } public int getYear() { return year; } public void setYear(int year) { this.year = year; }
  • 11. public String getCollege() { return college; } public void setCollege(String college) { this.college = college; } public int getCuCourses() { return cuCourses; } public void setCuCourses(int cuCourses) { this.cuCourses = cuCourses; } public int getTotalCourses() { return totalCourses; } public void setTotalCourses(int totalCourses) { this.totalCourses = totalCourses; } private int id; private String fname; private String lname; private int age; private double gpa; private int year; private String college; private int cuCourses; private int totalCourses; public Student(int id, String fname, String lname, int age, double gpa, int year, String college, int cuCourses, int totalCourses) { super(); this.id = id; this.fname = fname; this.lname = lname; this.age = age; this.gpa = gpa;
  • 12. this.year = year; this.college = college; this.cuCourses = cuCourses; this.totalCourses = totalCourses; } @Override public String toString() { return "Student [id=" + id + ", fname=" + fname + ", lname=" + lname + ", age=" + age + ", gpa=" + gpa + ", year=" + year + ", college=" + college + ", cuCourses=" + cuCourses + ", totalCourses=" + totalCourses + "] "; } }