SlideShare a Scribd company logo
1 of 3
Download to read offline
fix the error :
class Node{
int data;
Node next;
public Node(int data) {
this.data = data;
this.next = null;
}
}
class singlelinkedlist {
public Node head = null;
public Node tail = null;
public void addNode(int data) {
Node newNode = new Node(data);
if(head == null) {
head = newNode;
tail = newNode;
}
else {
tail.next = newNode;
tail = newNode;
}
}
public void sortList() {
Node current = head, index = null;
int temp;
if(head == null) {
return;
}
else {
while(current != null) {
index = current.next;
while(index != null) {
if(current.data > index.data) {
temp = current.data;
current.data = index.data;
index.data = temp;
}
index = index.next;
}
current = current.next;
}
}
}
public void display() {
Node current = head;
if(head == null) {
System.out.println("List is empty");
return;
}
while(current != null) {
System.out.print(current.data + " ");
current = current.next;
}
System.out.println();
}
}
public class JavaApplication46 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
SortList sList = new SortList();
sList.addNode(9);
sList.addNode(7);
sList.addNode(2);
sList.addNode(5);
sList.addNode(4);
System.out.println("Original list: ");
sList.display();
sList.sortList();
System.out.println("Sorted list: ");
sList.display();
}
}

More Related Content

Similar to fix the error - class Node{ int data- Node next-.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
tienlivick
 
Help I keep getting the same error when running a code. Below is the.pdf
Help I keep getting the same error when running a code. Below is the.pdfHelp I keep getting the same error when running a code. Below is the.pdf
Help I keep getting the same error when running a code. Below is the.pdf
mail931892
 
Data structures cs301 power point slides lecture 03
Data structures   cs301 power point slides lecture 03Data structures   cs301 power point slides lecture 03
Data structures cs301 power point slides lecture 03
Nasir Mehmood
 
Draw memory map of this link list code and add insert at last ( java)-.pdf
Draw memory map of this link list code and add insert at last ( java)-.pdfDraw memory map of this link list code and add insert at last ( java)-.pdf
Draw memory map of this link list code and add insert at last ( java)-.pdf
Andrew8IBPatersonk
 
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. .pdfRewrite 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
 
I need help implementing a Stack with this java programming assignme.pdf
I need help implementing a Stack with this java programming assignme.pdfI need help implementing a Stack with this java programming assignme.pdf
I need help implementing a Stack with this java programming assignme.pdf
sauravmanwanicp
 
NumberList.java (implements the linked list)public class NumberLis.pdf
NumberList.java (implements the linked list)public class NumberLis.pdfNumberList.java (implements the linked list)public class NumberLis.pdf
NumberList.java (implements the linked list)public class NumberLis.pdf
anjanacottonmills
 
Please refer this solution. This is working file for IntegersHeade.pdf
Please refer this solution. This is working file for IntegersHeade.pdfPlease refer this solution. This is working file for IntegersHeade.pdf
Please refer this solution. This is working file for IntegersHeade.pdf
sooryasalini
 
How to delete one specific node in linked list in CThanksSolu.pdf
How to delete one specific node in linked list in CThanksSolu.pdfHow to delete one specific node in linked list in CThanksSolu.pdf
How to delete one specific node in linked list in CThanksSolu.pdf
footstatus
 
public class SLLT { protected SLLNodeT head, tail; pub.pdf
public class SLLT {     protected SLLNodeT head, tail;     pub.pdfpublic class SLLT {     protected SLLNodeT head, tail;     pub.pdf
public class SLLT { protected SLLNodeT head, tail; pub.pdf
clarityvision
 
C# code pleaseWrite a program that creates a link list object of 1.pdf
C# code pleaseWrite a program that creates a link list object of 1.pdfC# code pleaseWrite a program that creates a link list object of 1.pdf
C# code pleaseWrite a program that creates a link list object of 1.pdf
duttakajal70
 
Here is the editable codeSolutionimport java.util.NoSuchEleme.pdf
Here is the editable codeSolutionimport java.util.NoSuchEleme.pdfHere is the editable codeSolutionimport java.util.NoSuchEleme.pdf
Here is the editable codeSolutionimport java.util.NoSuchEleme.pdf
arrowmobile
 
import java-util-Iterator- import java-util-NoSuchElementException- im.pdf
import java-util-Iterator- import java-util-NoSuchElementException- im.pdfimport java-util-Iterator- import java-util-NoSuchElementException- im.pdf
import java-util-Iterator- import java-util-NoSuchElementException- im.pdf
Stewart29UReesa
 
could you implement this function please, im having issues with it..pdf
could you implement this function please, im having issues with it..pdfcould you implement this function please, im having issues with it..pdf
could you implement this function please, im having issues with it..pdf
feroz544
 
hi i have to write a java program involving link lists. i have a pro.pdf
hi i have to write a java program involving link lists. i have a pro.pdfhi i have to write a java program involving link lists. i have a pro.pdf
hi i have to write a java program involving link lists. i have a pro.pdf
archgeetsenterprises
 

Similar to fix the error - class Node{ int data- Node next-.pdf (20)

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
 
Help I keep getting the same error when running a code. Below is the.pdf
Help I keep getting the same error when running a code. Below is the.pdfHelp I keep getting the same error when running a code. Below is the.pdf
Help I keep getting the same error when running a code. Below is the.pdf
 
137 Lab-2.2.pdf
137 Lab-2.2.pdf137 Lab-2.2.pdf
137 Lab-2.2.pdf
 
Linked Stack program.docx
Linked Stack program.docxLinked Stack program.docx
Linked Stack program.docx
 
Data structures cs301 power point slides lecture 03
Data structures   cs301 power point slides lecture 03Data structures   cs301 power point slides lecture 03
Data structures cs301 power point slides lecture 03
 
Draw memory map of this link list code and add insert at last ( java)-.pdf
Draw memory map of this link list code and add insert at last ( java)-.pdfDraw memory map of this link list code and add insert at last ( java)-.pdf
Draw memory map of this link list code and add insert at last ( java)-.pdf
 
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. .pdfRewrite 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
 
I need help implementing a Stack with this java programming assignme.pdf
I need help implementing a Stack with this java programming assignme.pdfI need help implementing a Stack with this java programming assignme.pdf
I need help implementing a Stack with this java programming assignme.pdf
 
NumberList.java (implements the linked list)public class NumberLis.pdf
NumberList.java (implements the linked list)public class NumberLis.pdfNumberList.java (implements the linked list)public class NumberLis.pdf
NumberList.java (implements the linked list)public class NumberLis.pdf
 
Please refer this solution. This is working file for IntegersHeade.pdf
Please refer this solution. This is working file for IntegersHeade.pdfPlease refer this solution. This is working file for IntegersHeade.pdf
Please refer this solution. This is working file for IntegersHeade.pdf
 
Lab-2.2 717822E504.pdf
Lab-2.2 717822E504.pdfLab-2.2 717822E504.pdf
Lab-2.2 717822E504.pdf
 
How to delete one specific node in linked list in CThanksSolu.pdf
How to delete one specific node in linked list in CThanksSolu.pdfHow to delete one specific node in linked list in CThanksSolu.pdf
How to delete one specific node in linked list in CThanksSolu.pdf
 
public class SLLT { protected SLLNodeT head, tail; pub.pdf
public class SLLT {     protected SLLNodeT head, tail;     pub.pdfpublic class SLLT {     protected SLLNodeT head, tail;     pub.pdf
public class SLLT { protected SLLNodeT head, tail; pub.pdf
 
C program to insert a node in doubly linked list
C program to insert a node in doubly linked listC program to insert a node in doubly linked list
C program to insert a node in doubly linked list
 
C# code pleaseWrite a program that creates a link list object of 1.pdf
C# code pleaseWrite a program that creates a link list object of 1.pdfC# code pleaseWrite a program that creates a link list object of 1.pdf
C# code pleaseWrite a program that creates a link list object of 1.pdf
 
Here is the editable codeSolutionimport java.util.NoSuchEleme.pdf
Here is the editable codeSolutionimport java.util.NoSuchEleme.pdfHere is the editable codeSolutionimport java.util.NoSuchEleme.pdf
Here is the editable codeSolutionimport java.util.NoSuchEleme.pdf
 
import java-util-Iterator- import java-util-NoSuchElementException- im.pdf
import java-util-Iterator- import java-util-NoSuchElementException- im.pdfimport java-util-Iterator- import java-util-NoSuchElementException- im.pdf
import java-util-Iterator- import java-util-NoSuchElementException- im.pdf
 
could you implement this function please, im having issues with it..pdf
could you implement this function please, im having issues with it..pdfcould you implement this function please, im having issues with it..pdf
could you implement this function please, im having issues with it..pdf
 
hi i have to write a java program involving link lists. i have a pro.pdf
hi i have to write a java program involving link lists. i have a pro.pdfhi i have to write a java program involving link lists. i have a pro.pdf
hi i have to write a java program involving link lists. i have a pro.pdf
 
This is to test a balanced tree. I need help testing an unbalanced t.pdf
This is to test a balanced tree. I need help testing an unbalanced t.pdfThis is to test a balanced tree. I need help testing an unbalanced t.pdf
This is to test a balanced tree. I need help testing an unbalanced t.pdf
 

More from AKVIGFOEU

For a quick review to see what you've learned- answer the following qu.pdf
For a quick review to see what you've learned- answer the following qu.pdfFor a quick review to see what you've learned- answer the following qu.pdf
For a quick review to see what you've learned- answer the following qu.pdf
AKVIGFOEU
 

More from AKVIGFOEU (20)

First explain how zygotic induction of lambda phage lysis occurs durin.pdf
First explain how zygotic induction of lambda phage lysis occurs durin.pdfFirst explain how zygotic induction of lambda phage lysis occurs durin.pdf
First explain how zygotic induction of lambda phage lysis occurs durin.pdf
 
finds that 11 of them have a travel time to work that is more than 60.pdf
finds that 11 of them have a travel time to work that is more than 60.pdffinds that 11 of them have a travel time to work that is more than 60.pdf
finds that 11 of them have a travel time to work that is more than 60.pdf
 
first image is matching- second image is selecting all that are correc.pdf
first image is matching- second image is selecting all that are correc.pdffirst image is matching- second image is selecting all that are correc.pdf
first image is matching- second image is selecting all that are correc.pdf
 
Fiona and Julianna are the owners of a small company- They are moving.pdf
Fiona and Julianna are the owners of a small company- They are moving.pdfFiona and Julianna are the owners of a small company- They are moving.pdf
Fiona and Julianna are the owners of a small company- They are moving.pdf
 
Find z-2 for -0-05-.pdf
Find z-2 for -0-05-.pdfFind z-2 for -0-05-.pdf
Find z-2 for -0-05-.pdf
 
Find z for -0-01 z- (Give the number with 2 decimals).pdf
Find z for -0-01 z- (Give the number with 2 decimals).pdfFind z for -0-01 z- (Give the number with 2 decimals).pdf
Find z for -0-01 z- (Give the number with 2 decimals).pdf
 
Fitry for Issuing Materials Materials issued are as follows- Joumalize.pdf
Fitry for Issuing Materials Materials issued are as follows- Joumalize.pdfFitry for Issuing Materials Materials issued are as follows- Joumalize.pdf
Fitry for Issuing Materials Materials issued are as follows- Joumalize.pdf
 
Firms that typically have a high degree of R&D intensity and growth op.pdf
Firms that typically have a high degree of R&D intensity and growth op.pdfFirms that typically have a high degree of R&D intensity and growth op.pdf
Firms that typically have a high degree of R&D intensity and growth op.pdf
 
Fiqure 1 below shows a plant cell as seen under an electron microscope.pdf
Fiqure 1 below shows a plant cell as seen under an electron microscope.pdfFiqure 1 below shows a plant cell as seen under an electron microscope.pdf
Fiqure 1 below shows a plant cell as seen under an electron microscope.pdf
 
Finding Population Statistics In Exercises 13 and 14 - find the range- (1).pdf
Finding Population Statistics In Exercises 13 and 14 - find the range- (1).pdfFinding Population Statistics In Exercises 13 and 14 - find the range- (1).pdf
Finding Population Statistics In Exercises 13 and 14 - find the range- (1).pdf
 
First steps Step 1- Pick a domain Step 2- Pose questions Step 3- Find.pdf
First steps  Step 1- Pick a domain Step 2- Pose questions Step 3- Find.pdfFirst steps  Step 1- Pick a domain Step 2- Pose questions Step 3- Find.pdf
First steps Step 1- Pick a domain Step 2- Pose questions Step 3- Find.pdf
 
For Dear Orleans Restaurant- the gross earnings of its employees total.pdf
For Dear Orleans Restaurant- the gross earnings of its employees total.pdfFor Dear Orleans Restaurant- the gross earnings of its employees total.pdf
For Dear Orleans Restaurant- the gross earnings of its employees total.pdf
 
For DePaul inc- what is the average return for the four years (we view.pdf
For DePaul inc- what is the average return for the four years (we view.pdfFor DePaul inc- what is the average return for the four years (we view.pdf
For DePaul inc- what is the average return for the four years (we view.pdf
 
For a three-way factorial ANOVA- how many interactions terms and assoc.pdf
For a three-way factorial ANOVA- how many interactions terms and assoc.pdfFor a three-way factorial ANOVA- how many interactions terms and assoc.pdf
For a three-way factorial ANOVA- how many interactions terms and assoc.pdf
 
Find the time for each figure below (AF)- Hint- from earliest to lates.pdf
Find the time for each figure below (AF)- Hint- from earliest to lates.pdfFind the time for each figure below (AF)- Hint- from earliest to lates.pdf
Find the time for each figure below (AF)- Hint- from earliest to lates.pdf
 
For a standard normal distribution- find- P(1-9-z-1-16).pdf
For a standard normal distribution- find- P(1-9-z-1-16).pdfFor a standard normal distribution- find- P(1-9-z-1-16).pdf
For a standard normal distribution- find- P(1-9-z-1-16).pdf
 
For a successful VoIP implementation- how important is it for the IT d.pdf
For a successful VoIP implementation- how important is it for the IT d.pdfFor a successful VoIP implementation- how important is it for the IT d.pdf
For a successful VoIP implementation- how important is it for the IT d.pdf
 
For a quick review to see what you've learned- answer the following qu.pdf
For a quick review to see what you've learned- answer the following qu.pdfFor a quick review to see what you've learned- answer the following qu.pdf
For a quick review to see what you've learned- answer the following qu.pdf
 
For a quarterly time series over the last 3 years (Year 1- Year 2- Yea.pdf
For a quarterly time series over the last 3 years (Year 1- Year 2- Yea.pdfFor a quarterly time series over the last 3 years (Year 1- Year 2- Yea.pdf
For a quarterly time series over the last 3 years (Year 1- Year 2- Yea.pdf
 
For a population with a standard deviation of -4- a z-score of z-0-50.pdf
For a population with a standard deviation of -4- a z-score of z-0-50.pdfFor a population with a standard deviation of -4- a z-score of z-0-50.pdf
For a population with a standard deviation of -4- a z-score of z-0-50.pdf
 

Recently uploaded

Orientation Canvas Course Presentation.pdf
Orientation Canvas Course Presentation.pdfOrientation Canvas Course Presentation.pdf
Orientation Canvas Course Presentation.pdf
Elizabeth Walsh
 
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
EADTU
 
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lessonQUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
httgc7rh9c
 
SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code Examples
Peter Brusilovsky
 

Recently uploaded (20)

Details on CBSE Compartment Exam.pptx1111
Details on CBSE Compartment Exam.pptx1111Details on CBSE Compartment Exam.pptx1111
Details on CBSE Compartment Exam.pptx1111
 
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
 
What is 3 Way Matching Process in Odoo 17.pptx
What is 3 Way Matching Process in Odoo 17.pptxWhat is 3 Way Matching Process in Odoo 17.pptx
What is 3 Way Matching Process in Odoo 17.pptx
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
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
 
Orientation Canvas Course Presentation.pdf
Orientation Canvas Course Presentation.pdfOrientation Canvas Course Presentation.pdf
Orientation Canvas Course Presentation.pdf
 
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
 
Ernest Hemingway's For Whom the Bell Tolls
Ernest Hemingway's For Whom the Bell TollsErnest Hemingway's For Whom the Bell Tolls
Ernest Hemingway's For Whom the Bell Tolls
 
diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
 
Play hard learn harder: The Serious Business of Play
Play hard learn harder:  The Serious Business of PlayPlay hard learn harder:  The Serious Business of Play
Play hard learn harder: The Serious Business of Play
 
Model Attribute _rec_name in the Odoo 17
Model Attribute _rec_name in the Odoo 17Model Attribute _rec_name in the Odoo 17
Model Attribute _rec_name in the Odoo 17
 
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
 
Introduction to TechSoup’s Digital Marketing Services and Use Cases
Introduction to TechSoup’s Digital Marketing  Services and Use CasesIntroduction to TechSoup’s Digital Marketing  Services and Use Cases
Introduction to TechSoup’s Digital Marketing Services and Use Cases
 
Observing-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxObserving-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptx
 
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
 
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lessonQUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
 
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
 
SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code Examples
 

fix the error - class Node{ int data- Node next-.pdf

  • 1. fix the error : class Node{ int data; Node next; public Node(int data) { this.data = data; this.next = null; } } class singlelinkedlist { public Node head = null; public Node tail = null; public void addNode(int data) { Node newNode = new Node(data); if(head == null) { head = newNode; tail = newNode; } else { tail.next = newNode; tail = newNode; } } public void sortList() { Node current = head, index = null; int temp; if(head == null) { return; } else { while(current != null) { index = current.next; while(index != null) {
  • 2. if(current.data > index.data) { temp = current.data; current.data = index.data; index.data = temp; } index = index.next; } current = current.next; } } } public void display() { Node current = head; if(head == null) { System.out.println("List is empty"); return; } while(current != null) { System.out.print(current.data + " "); current = current.next; } System.out.println(); } } public class JavaApplication46 { /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here SortList sList = new SortList(); sList.addNode(9); sList.addNode(7); sList.addNode(2); sList.addNode(5); sList.addNode(4);