SlideShare a Scribd company logo
//Node for list storage.
class Ndd
{
int data;
Ndd next;
Ndd(int d)
{
data = d;
next = null;
}
}
//linked list operations.
class lnklist
{
Ndd hads;
//method to swap nodes..
public void swpNds(int xvv, int yvv)
{
//check two node values,if equal no need of shifting.
if (xvv == yvv) return;
Ndd prevX = null, currX = hads;
while (currX != null && currX.data != xvv)
{
prevX = currX;
currX = currX.next;
}
Ndd prevY = null, currY = hads;
while (currY != null && currY.data != yvv)
{
prevY = currY;
currY = currY.next;
}
if (currX == null || currY == null)
return;
if (prevX != null)
prevX.next = currY;
else
hads = currY;
if (prevY != null)
prevY.next = currX;
else
hads = currX;
Ndd temp = currX.next;
currX.next = currY.next;
currY.next = temp;
}
public void push(int nwd-ata)
{
Ndd nw-nd = new Ndd(nwd-ata);
nw-nd.next = hads;
hads = nw-nd;
}
public void prntList()
{
Ndd tNode = hads;
while (tNode != null)
{
System.out.print(tNode.data+" ");
tNode = tNode.next;
}
}
public static void main(String[] ssds)
{
lnklist llist = new lnklist();
llist.push(7);
llist.push(6);
llist.push(5);
llist.push(4);
llist.push(3);
llist.push(2);
llist.push(1);
System.out.print(" Linked list before calling swpNds() ");
llist.prntList();
llist.swpNds(4, 3);
System.out.print(" Linked list after calling swpNds() ");
llist.prntList();
}
}
Solution
//Node for list storage.
class Ndd
{
int data;
Ndd next;
Ndd(int d)
{
data = d;
next = null;
}
}
//linked list operations.
class lnklist
{
Ndd hads;
//method to swap nodes..
public void swpNds(int xvv, int yvv)
{
//check two node values,if equal no need of shifting.
if (xvv == yvv) return;
Ndd prevX = null, currX = hads;
while (currX != null && currX.data != xvv)
{
prevX = currX;
currX = currX.next;
}
Ndd prevY = null, currY = hads;
while (currY != null && currY.data != yvv)
{
prevY = currY;
currY = currY.next;
}
if (currX == null || currY == null)
return;
if (prevX != null)
prevX.next = currY;
else
hads = currY;
if (prevY != null)
prevY.next = currX;
else
hads = currX;
Ndd temp = currX.next;
currX.next = currY.next;
currY.next = temp;
}
public void push(int nwd-ata)
{
Ndd nw-nd = new Ndd(nwd-ata);
nw-nd.next = hads;
hads = nw-nd;
}
public void prntList()
{
Ndd tNode = hads;
while (tNode != null)
{
System.out.print(tNode.data+" ");
tNode = tNode.next;
}
}
public static void main(String[] ssds)
{
lnklist llist = new lnklist();
llist.push(7);
llist.push(6);
llist.push(5);
llist.push(4);
llist.push(3);
llist.push(2);
llist.push(1);
System.out.print(" Linked list before calling swpNds() ");
llist.prntList();
llist.swpNds(4, 3);
System.out.print(" Linked list after calling swpNds() ");
llist.prntList();
}
}

More Related Content

More from anjaniar7gallery

pH + pOH = 14 pOH = 4.5 [OH-] = 10-4.5Fe(OH)2 --- Fe2+ + 2 O.pdf
pH + pOH = 14 pOH = 4.5 [OH-] = 10-4.5Fe(OH)2 --- Fe2+ + 2 O.pdfpH + pOH = 14 pOH = 4.5 [OH-] = 10-4.5Fe(OH)2 --- Fe2+ + 2 O.pdf
pH + pOH = 14 pOH = 4.5 [OH-] = 10-4.5Fe(OH)2 --- Fe2+ + 2 O.pdf
anjaniar7gallery
 
Laser ScanningLaser scanning is an emerging data acquisition techn.pdf
Laser ScanningLaser scanning is an emerging data acquisition techn.pdfLaser ScanningLaser scanning is an emerging data acquisition techn.pdf
Laser ScanningLaser scanning is an emerging data acquisition techn.pdf
anjaniar7gallery
 
InternetService.java import java.text.DecimalFormat; import jav.pdf
InternetService.java  import java.text.DecimalFormat; import jav.pdfInternetService.java  import java.text.DecimalFormat; import jav.pdf
InternetService.java import java.text.DecimalFormat; import jav.pdf
anjaniar7gallery
 
Importance of planning to the practice of managementSolutionIm.pdf
Importance of planning to the practice of managementSolutionIm.pdfImportance of planning to the practice of managementSolutionIm.pdf
Importance of planning to the practice of managementSolutionIm.pdf
anjaniar7gallery
 
Hardware refers to all of the physical parts of a computer system. F.pdf
Hardware refers to all of the physical parts of a computer system. F.pdfHardware refers to all of the physical parts of a computer system. F.pdf
Hardware refers to all of the physical parts of a computer system. F.pdf
anjaniar7gallery
 
Events after the reporting period are those events favorable and unf.pdf
Events after the reporting period are those events favorable and unf.pdfEvents after the reporting period are those events favorable and unf.pdf
Events after the reporting period are those events favorable and unf.pdf
anjaniar7gallery
 
D is correctSolutionD is correct.pdf
D is correctSolutionD is correct.pdfD is correctSolutionD is correct.pdf
D is correctSolutionD is correct.pdf
anjaniar7gallery
 
Cost centersCost centers are Centers that incur costs for operati.pdf
Cost centersCost centers are Centers that incur costs for operati.pdfCost centersCost centers are Centers that incur costs for operati.pdf
Cost centersCost centers are Centers that incur costs for operati.pdf
anjaniar7gallery
 
Calcium Phosphate is a slightly soluble salt. Here isthe equation fo.pdf
Calcium Phosphate is a slightly soluble salt. Here isthe equation fo.pdfCalcium Phosphate is a slightly soluble salt. Here isthe equation fo.pdf
Calcium Phosphate is a slightly soluble salt. Here isthe equation fo.pdf
anjaniar7gallery
 
c.250Solutionc.250.pdf
c.250Solutionc.250.pdfc.250Solutionc.250.pdf
c.250Solutionc.250.pdf
anjaniar7gallery
 
#! usrbinpython def Flatten(list) newList = [] for i in ra.pdf
#! usrbinpython def Flatten(list) newList = [] for i in ra.pdf#! usrbinpython def Flatten(list) newList = [] for i in ra.pdf
#! usrbinpython def Flatten(list) newList = [] for i in ra.pdf
anjaniar7gallery
 
a) Two domains are OD1 and OD2 domains. The common function of OD1 a.pdf
a) Two domains are OD1 and OD2 domains. The common function of OD1 a.pdfa) Two domains are OD1 and OD2 domains. The common function of OD1 a.pdf
a) Two domains are OD1 and OD2 domains. The common function of OD1 a.pdf
anjaniar7gallery
 
200 students attended session I.150 students attended session II..pdf
200 students attended session I.150 students attended session II..pdf200 students attended session I.150 students attended session II..pdf
200 students attended session I.150 students attended session II..pdf
anjaniar7gallery
 
Step1 Find energy of one photon=(Planck constantx.pdf
                     Step1 Find energy of one photon=(Planck constantx.pdf                     Step1 Find energy of one photon=(Planck constantx.pdf
Step1 Find energy of one photon=(Planck constantx.pdf
anjaniar7gallery
 
Cost Method Journal Entry Date Account Head and Entry Debit .pdf
    Cost Method Journal Entry      Date Account Head and Entry Debit .pdf    Cost Method Journal Entry      Date Account Head and Entry Debit .pdf
Cost Method Journal Entry Date Account Head and Entry Debit .pdf
anjaniar7gallery
 
Non-polar - Waterproof Covalently bonded - strong.pdf
                     Non-polar - Waterproof Covalently bonded - strong.pdf                     Non-polar - Waterproof Covalently bonded - strong.pdf
Non-polar - Waterproof Covalently bonded - strong.pdf
anjaniar7gallery
 
Hygroscopy is the ability of a substance to attra.pdf
                     Hygroscopy is the ability of a substance to attra.pdf                     Hygroscopy is the ability of a substance to attra.pdf
Hygroscopy is the ability of a substance to attra.pdf
anjaniar7gallery
 
H2SO4 + Cd(OH)2 = 2H2O + CdSO4 In this reaction, .pdf
                     H2SO4 + Cd(OH)2 = 2H2O + CdSO4 In this reaction, .pdf                     H2SO4 + Cd(OH)2 = 2H2O + CdSO4 In this reaction, .pdf
H2SO4 + Cd(OH)2 = 2H2O + CdSO4 In this reaction, .pdf
anjaniar7gallery
 
c. SO2. S shares 8 electrons total with the two O.pdf
                     c. SO2. S shares 8 electrons total with the two O.pdf                     c. SO2. S shares 8 electrons total with the two O.pdf
c. SO2. S shares 8 electrons total with the two O.pdf
anjaniar7gallery
 
a. Assuming complete dissociation, we can have [O.pdf
                     a. Assuming complete dissociation, we can have [O.pdf                     a. Assuming complete dissociation, we can have [O.pdf
a. Assuming complete dissociation, we can have [O.pdf
anjaniar7gallery
 

More from anjaniar7gallery (20)

pH + pOH = 14 pOH = 4.5 [OH-] = 10-4.5Fe(OH)2 --- Fe2+ + 2 O.pdf
pH + pOH = 14 pOH = 4.5 [OH-] = 10-4.5Fe(OH)2 --- Fe2+ + 2 O.pdfpH + pOH = 14 pOH = 4.5 [OH-] = 10-4.5Fe(OH)2 --- Fe2+ + 2 O.pdf
pH + pOH = 14 pOH = 4.5 [OH-] = 10-4.5Fe(OH)2 --- Fe2+ + 2 O.pdf
 
Laser ScanningLaser scanning is an emerging data acquisition techn.pdf
Laser ScanningLaser scanning is an emerging data acquisition techn.pdfLaser ScanningLaser scanning is an emerging data acquisition techn.pdf
Laser ScanningLaser scanning is an emerging data acquisition techn.pdf
 
InternetService.java import java.text.DecimalFormat; import jav.pdf
InternetService.java  import java.text.DecimalFormat; import jav.pdfInternetService.java  import java.text.DecimalFormat; import jav.pdf
InternetService.java import java.text.DecimalFormat; import jav.pdf
 
Importance of planning to the practice of managementSolutionIm.pdf
Importance of planning to the practice of managementSolutionIm.pdfImportance of planning to the practice of managementSolutionIm.pdf
Importance of planning to the practice of managementSolutionIm.pdf
 
Hardware refers to all of the physical parts of a computer system. F.pdf
Hardware refers to all of the physical parts of a computer system. F.pdfHardware refers to all of the physical parts of a computer system. F.pdf
Hardware refers to all of the physical parts of a computer system. F.pdf
 
Events after the reporting period are those events favorable and unf.pdf
Events after the reporting period are those events favorable and unf.pdfEvents after the reporting period are those events favorable and unf.pdf
Events after the reporting period are those events favorable and unf.pdf
 
D is correctSolutionD is correct.pdf
D is correctSolutionD is correct.pdfD is correctSolutionD is correct.pdf
D is correctSolutionD is correct.pdf
 
Cost centersCost centers are Centers that incur costs for operati.pdf
Cost centersCost centers are Centers that incur costs for operati.pdfCost centersCost centers are Centers that incur costs for operati.pdf
Cost centersCost centers are Centers that incur costs for operati.pdf
 
Calcium Phosphate is a slightly soluble salt. Here isthe equation fo.pdf
Calcium Phosphate is a slightly soluble salt. Here isthe equation fo.pdfCalcium Phosphate is a slightly soluble salt. Here isthe equation fo.pdf
Calcium Phosphate is a slightly soluble salt. Here isthe equation fo.pdf
 
c.250Solutionc.250.pdf
c.250Solutionc.250.pdfc.250Solutionc.250.pdf
c.250Solutionc.250.pdf
 
#! usrbinpython def Flatten(list) newList = [] for i in ra.pdf
#! usrbinpython def Flatten(list) newList = [] for i in ra.pdf#! usrbinpython def Flatten(list) newList = [] for i in ra.pdf
#! usrbinpython def Flatten(list) newList = [] for i in ra.pdf
 
a) Two domains are OD1 and OD2 domains. The common function of OD1 a.pdf
a) Two domains are OD1 and OD2 domains. The common function of OD1 a.pdfa) Two domains are OD1 and OD2 domains. The common function of OD1 a.pdf
a) Two domains are OD1 and OD2 domains. The common function of OD1 a.pdf
 
200 students attended session I.150 students attended session II..pdf
200 students attended session I.150 students attended session II..pdf200 students attended session I.150 students attended session II..pdf
200 students attended session I.150 students attended session II..pdf
 
Step1 Find energy of one photon=(Planck constantx.pdf
                     Step1 Find energy of one photon=(Planck constantx.pdf                     Step1 Find energy of one photon=(Planck constantx.pdf
Step1 Find energy of one photon=(Planck constantx.pdf
 
Cost Method Journal Entry Date Account Head and Entry Debit .pdf
    Cost Method Journal Entry      Date Account Head and Entry Debit .pdf    Cost Method Journal Entry      Date Account Head and Entry Debit .pdf
Cost Method Journal Entry Date Account Head and Entry Debit .pdf
 
Non-polar - Waterproof Covalently bonded - strong.pdf
                     Non-polar - Waterproof Covalently bonded - strong.pdf                     Non-polar - Waterproof Covalently bonded - strong.pdf
Non-polar - Waterproof Covalently bonded - strong.pdf
 
Hygroscopy is the ability of a substance to attra.pdf
                     Hygroscopy is the ability of a substance to attra.pdf                     Hygroscopy is the ability of a substance to attra.pdf
Hygroscopy is the ability of a substance to attra.pdf
 
H2SO4 + Cd(OH)2 = 2H2O + CdSO4 In this reaction, .pdf
                     H2SO4 + Cd(OH)2 = 2H2O + CdSO4 In this reaction, .pdf                     H2SO4 + Cd(OH)2 = 2H2O + CdSO4 In this reaction, .pdf
H2SO4 + Cd(OH)2 = 2H2O + CdSO4 In this reaction, .pdf
 
c. SO2. S shares 8 electrons total with the two O.pdf
                     c. SO2. S shares 8 electrons total with the two O.pdf                     c. SO2. S shares 8 electrons total with the two O.pdf
c. SO2. S shares 8 electrons total with the two O.pdf
 
a. Assuming complete dissociation, we can have [O.pdf
                     a. Assuming complete dissociation, we can have [O.pdf                     a. Assuming complete dissociation, we can have [O.pdf
a. Assuming complete dissociation, we can have [O.pdf
 

Recently uploaded

Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
vaibhavrinwa19
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
TechSoup
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
CarlosHernanMontoyab2
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
EduSkills OECD
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
Jheel Barad
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
BhavyaRajput3
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 

Recently uploaded (20)

Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 

Node for list storage. class Ndd { int data; Ndd next; N.pdf

  • 1. //Node for list storage. class Ndd { int data; Ndd next; Ndd(int d) { data = d; next = null; } } //linked list operations. class lnklist { Ndd hads; //method to swap nodes.. public void swpNds(int xvv, int yvv) { //check two node values,if equal no need of shifting. if (xvv == yvv) return; Ndd prevX = null, currX = hads; while (currX != null && currX.data != xvv) { prevX = currX; currX = currX.next; } Ndd prevY = null, currY = hads; while (currY != null && currY.data != yvv) { prevY = currY; currY = currY.next;
  • 2. } if (currX == null || currY == null) return; if (prevX != null) prevX.next = currY; else hads = currY; if (prevY != null) prevY.next = currX; else hads = currX; Ndd temp = currX.next; currX.next = currY.next; currY.next = temp; } public void push(int nwd-ata) { Ndd nw-nd = new Ndd(nwd-ata); nw-nd.next = hads; hads = nw-nd; } public void prntList() {
  • 3. Ndd tNode = hads; while (tNode != null) { System.out.print(tNode.data+" "); tNode = tNode.next; } } public static void main(String[] ssds) { lnklist llist = new lnklist(); llist.push(7); llist.push(6); llist.push(5); llist.push(4); llist.push(3); llist.push(2); llist.push(1); System.out.print(" Linked list before calling swpNds() "); llist.prntList(); llist.swpNds(4, 3); System.out.print(" Linked list after calling swpNds() "); llist.prntList(); } } Solution //Node for list storage. class Ndd { int data;
  • 4. Ndd next; Ndd(int d) { data = d; next = null; } } //linked list operations. class lnklist { Ndd hads; //method to swap nodes.. public void swpNds(int xvv, int yvv) { //check two node values,if equal no need of shifting. if (xvv == yvv) return; Ndd prevX = null, currX = hads; while (currX != null && currX.data != xvv) { prevX = currX; currX = currX.next; } Ndd prevY = null, currY = hads; while (currY != null && currY.data != yvv) { prevY = currY; currY = currY.next; } if (currX == null || currY == null) return;
  • 5. if (prevX != null) prevX.next = currY; else hads = currY; if (prevY != null) prevY.next = currX; else hads = currX; Ndd temp = currX.next; currX.next = currY.next; currY.next = temp; } public void push(int nwd-ata) { Ndd nw-nd = new Ndd(nwd-ata); nw-nd.next = hads; hads = nw-nd; } public void prntList() { Ndd tNode = hads; while (tNode != null) { System.out.print(tNode.data+" "); tNode = tNode.next;
  • 6. } } public static void main(String[] ssds) { lnklist llist = new lnklist(); llist.push(7); llist.push(6); llist.push(5); llist.push(4); llist.push(3); llist.push(2); llist.push(1); System.out.print(" Linked list before calling swpNds() "); llist.prntList(); llist.swpNds(4, 3); System.out.print(" Linked list after calling swpNds() "); llist.prntList(); } }