SlideShare a Scribd company logo
1 of 3
Download to read offline
// Adding elements
public void add(String element) {
// For first element Head is null. So, create a new node and mark it as head.
// and increase numElements
if(head == null){
head = new StringNode(element, null);
numElements++;
} else {
// if not, find its place first.
// then create a node and mark position link to new node
// mark new node as link to positional node
StringNode node = head;
while(node.getLink() != null){
if(node.getData().compareTo(element) < 0){
break;
}
}
StringNode newNode = new StringNode(element, null);
newNode.setLink(node.getLink());
node.setLink(newNode);
numElements++;
}
}
// Removing elements
public boolean remove(String target)
{
StringNode targetNode = head;
boolean found = false;
while (targetNode!= null && !found)
{
if(targetNode.getData().equalsIgnoreCase(target))
found = true;
else
targetNode = targetNode.getLink();
}
if(found)
{
// copy the head to targetNode
// and then advance head to the next node.
targetNode.setData(targetNode.getLink().getData());
targetNode.setLink(targetNode.getLink());
numElements --;
}
return found;
}
Solution
// Adding elements
public void add(String element) {
// For first element Head is null. So, create a new node and mark it as head.
// and increase numElements
if(head == null){
head = new StringNode(element, null);
numElements++;
} else {
// if not, find its place first.
// then create a node and mark position link to new node
// mark new node as link to positional node
StringNode node = head;
while(node.getLink() != null){
if(node.getData().compareTo(element) < 0){
break;
}
}
StringNode newNode = new StringNode(element, null);
newNode.setLink(node.getLink());
node.setLink(newNode);
numElements++;
}
}
// Removing elements
public boolean remove(String target)
{
StringNode targetNode = head;
boolean found = false;
while (targetNode!= null && !found)
{
if(targetNode.getData().equalsIgnoreCase(target))
found = true;
else
targetNode = targetNode.getLink();
}
if(found)
{
// copy the head to targetNode
// and then advance head to the next node.
targetNode.setData(targetNode.getLink().getData());
targetNode.setLink(targetNode.getLink());
numElements --;
}
return found;
}

More Related Content

Similar to Adding elements public void add(String element) { For fi.pdf

I have been tasked to write a code for a Singly Linked list that inc.pdf
I have been tasked to write a code for a Singly Linked list that inc.pdfI have been tasked to write a code for a Singly Linked list that inc.pdf
I have been tasked to write a code for a Singly Linked list that inc.pdfarkmuzikllc
 
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.pdfsooryasalini
 
linked List.docx vhjgvjhvgjhjhbbjkhkjhkjh
linked List.docx vhjgvjhvgjhjhbbjkhkjhkjhlinked List.docx vhjgvjhvgjhjhbbjkhkjhkjh
linked List.docx vhjgvjhvgjhjhbbjkhkjhkjhvasavim9
 
Please write in C++ and should be able to compile and debug.Thank yo.pdf
Please write in C++ and should be able to compile and debug.Thank yo.pdfPlease write in C++ and should be able to compile and debug.Thank yo.pdf
Please write in C++ and should be able to compile and debug.Thank yo.pdfajaycosmeticslg
 
Please find my implementationpublic KeyedItem remove() { DO.pdf
Please find my implementationpublic KeyedItem remove() { DO.pdfPlease find my implementationpublic KeyedItem remove() { DO.pdf
Please find my implementationpublic KeyedItem remove() { DO.pdfanjaliselectionahd
 
import java.util.Iterator; import java.util.NoSuchElementException; .pdf
  import java.util.Iterator; import java.util.NoSuchElementException; .pdf  import java.util.Iterator; import java.util.NoSuchElementException; .pdf
import java.util.Iterator; import java.util.NoSuchElementException; .pdfdeepakangel
 
You can list anything, it doesnt matter. I just want to see code f.pdf
You can list anything, it doesnt matter. I just want to see code f.pdfYou can list anything, it doesnt matter. I just want to see code f.pdf
You can list anything, it doesnt matter. I just want to see code f.pdffashionbigchennai
 
please help me in C++Objective Create a singly linked list of num.pdf
please help me in C++Objective Create a singly linked list of num.pdfplease help me in C++Objective Create a singly linked list of num.pdf
please help me in C++Objective Create a singly linked list of num.pdfaminbijal86
 
You are required to implement the following functions for doubly linke.docx
You are required to implement the following functions for doubly linke.docxYou are required to implement the following functions for doubly linke.docx
You are required to implement the following functions for doubly linke.docxJonathan5GxRossk
 
Program to insert in a sorted list #includestdio.h#include.pdf
 Program to insert in a sorted list #includestdio.h#include.pdf Program to insert in a sorted list #includestdio.h#include.pdf
Program to insert in a sorted list #includestdio.h#include.pdfsudhirchourasia86
 
How to do the main method for this programBinaryNode.javapublic.pdf
How to do the main method for this programBinaryNode.javapublic.pdfHow to do the main method for this programBinaryNode.javapublic.pdf
How to do the main method for this programBinaryNode.javapublic.pdffeelingcomputors
 
Write the following using javaGiven a class ‘Node’ and ‘NodeList’,.pdf
Write the following using javaGiven a class ‘Node’ and ‘NodeList’,.pdfWrite the following using javaGiven a class ‘Node’ and ‘NodeList’,.pdf
Write the following using javaGiven a class ‘Node’ and ‘NodeList’,.pdffathimalinks
 
Given below is the completed implementation of MyLinkedList class. O.pdf
Given below is the completed implementation of MyLinkedList class. O.pdfGiven below is the completed implementation of MyLinkedList class. O.pdf
Given below is the completed implementation of MyLinkedList class. O.pdfinfo430661
 
5. Design and implement a method contains 2 for BinarySearchTree, fu.pdf
5. Design and implement a method contains 2 for BinarySearchTree, fu.pdf5. Design and implement a method contains 2 for BinarySearchTree, fu.pdf
5. Design and implement a method contains 2 for BinarySearchTree, fu.pdframbagra74
 
The LinkedList1 class implements a Linked list. class.pdf
The LinkedList1 class implements a Linked list. class.pdfThe LinkedList1 class implements a Linked list. class.pdf
The LinkedList1 class implements a Linked list. class.pdfmalavshah9013
 
Given a newly created Binary Search Tree with the following numerica.pdf
Given a newly created Binary Search Tree with the following numerica.pdfGiven a newly created Binary Search Tree with the following numerica.pdf
Given a newly created Binary Search Tree with the following numerica.pdfhadpadrrajeshh
 
Data Structures in C++I am really new to C++, so links are really .pdf
Data Structures in C++I am really new to C++, so links are really .pdfData Structures in C++I am really new to C++, so links are really .pdf
Data Structures in C++I am really new to C++, so links are really .pdfrohit219406
 
C code on linked list #include stdio.h #include stdlib.h.pdf
 C code on linked list #include stdio.h #include stdlib.h.pdf C code on linked list #include stdio.h #include stdlib.h.pdf
C code on linked list #include stdio.h #include stdlib.h.pdfdeepua8
 

Similar to Adding elements public void add(String element) { For fi.pdf (20)

I have been tasked to write a code for a Singly Linked list that inc.pdf
I have been tasked to write a code for a Singly Linked list that inc.pdfI have been tasked to write a code for a Singly Linked list that inc.pdf
I have been tasked to write a code for a Singly Linked list that inc.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
 
linked List.docx vhjgvjhvgjhjhbbjkhkjhkjh
linked List.docx vhjgvjhvgjhjhbbjkhkjhkjhlinked List.docx vhjgvjhvgjhjhbbjkhkjhkjh
linked List.docx vhjgvjhvgjhjhbbjkhkjhkjh
 
Please write in C++ and should be able to compile and debug.Thank yo.pdf
Please write in C++ and should be able to compile and debug.Thank yo.pdfPlease write in C++ and should be able to compile and debug.Thank yo.pdf
Please write in C++ and should be able to compile and debug.Thank yo.pdf
 
Please find my implementationpublic KeyedItem remove() { DO.pdf
Please find my implementationpublic KeyedItem remove() { DO.pdfPlease find my implementationpublic KeyedItem remove() { DO.pdf
Please find my implementationpublic KeyedItem remove() { DO.pdf
 
import java.util.Iterator; import java.util.NoSuchElementException; .pdf
  import java.util.Iterator; import java.util.NoSuchElementException; .pdf  import java.util.Iterator; import java.util.NoSuchElementException; .pdf
import java.util.Iterator; import java.util.NoSuchElementException; .pdf
 
Lab-2.4 101.pdf
Lab-2.4 101.pdfLab-2.4 101.pdf
Lab-2.4 101.pdf
 
You can list anything, it doesnt matter. I just want to see code f.pdf
You can list anything, it doesnt matter. I just want to see code f.pdfYou can list anything, it doesnt matter. I just want to see code f.pdf
You can list anything, it doesnt matter. I just want to see code f.pdf
 
please help me in C++Objective Create a singly linked list of num.pdf
please help me in C++Objective Create a singly linked list of num.pdfplease help me in C++Objective Create a singly linked list of num.pdf
please help me in C++Objective Create a singly linked list of num.pdf
 
You are required to implement the following functions for doubly linke.docx
You are required to implement the following functions for doubly linke.docxYou are required to implement the following functions for doubly linke.docx
You are required to implement the following functions for doubly linke.docx
 
Program to insert in a sorted list #includestdio.h#include.pdf
 Program to insert in a sorted list #includestdio.h#include.pdf Program to insert in a sorted list #includestdio.h#include.pdf
Program to insert in a sorted list #includestdio.h#include.pdf
 
How to do the main method for this programBinaryNode.javapublic.pdf
How to do the main method for this programBinaryNode.javapublic.pdfHow to do the main method for this programBinaryNode.javapublic.pdf
How to do the main method for this programBinaryNode.javapublic.pdf
 
Write the following using javaGiven a class ‘Node’ and ‘NodeList’,.pdf
Write the following using javaGiven a class ‘Node’ and ‘NodeList’,.pdfWrite the following using javaGiven a class ‘Node’ and ‘NodeList’,.pdf
Write the following using javaGiven a class ‘Node’ and ‘NodeList’,.pdf
 
Given below is the completed implementation of MyLinkedList class. O.pdf
Given below is the completed implementation of MyLinkedList class. O.pdfGiven below is the completed implementation of MyLinkedList class. O.pdf
Given below is the completed implementation of MyLinkedList class. O.pdf
 
5. Design and implement a method contains 2 for BinarySearchTree, fu.pdf
5. Design and implement a method contains 2 for BinarySearchTree, fu.pdf5. Design and implement a method contains 2 for BinarySearchTree, fu.pdf
5. Design and implement a method contains 2 for BinarySearchTree, fu.pdf
 
dynamicList.ppt
dynamicList.pptdynamicList.ppt
dynamicList.ppt
 
The LinkedList1 class implements a Linked list. class.pdf
The LinkedList1 class implements a Linked list. class.pdfThe LinkedList1 class implements a Linked list. class.pdf
The LinkedList1 class implements a Linked list. class.pdf
 
Given a newly created Binary Search Tree with the following numerica.pdf
Given a newly created Binary Search Tree with the following numerica.pdfGiven a newly created Binary Search Tree with the following numerica.pdf
Given a newly created Binary Search Tree with the following numerica.pdf
 
Data Structures in C++I am really new to C++, so links are really .pdf
Data Structures in C++I am really new to C++, so links are really .pdfData Structures in C++I am really new to C++, so links are really .pdf
Data Structures in C++I am really new to C++, so links are really .pdf
 
C code on linked list #include stdio.h #include stdlib.h.pdf
 C code on linked list #include stdio.h #include stdlib.h.pdf C code on linked list #include stdio.h #include stdlib.h.pdf
C code on linked list #include stdio.h #include stdlib.h.pdf
 

More from aparnacollection

What is an OS • Interface between application programs and hardwa.pdf
What is an OS • Interface between application programs and hardwa.pdfWhat is an OS • Interface between application programs and hardwa.pdf
What is an OS • Interface between application programs and hardwa.pdfaparnacollection
 
Using a broad definition of file(note that it doesnt count h.pdf
Using a broad definition of file(note that it doesnt count h.pdfUsing a broad definition of file(note that it doesnt count h.pdf
Using a broad definition of file(note that it doesnt count h.pdfaparnacollection
 
unable to open it ....it asks for username and passwordSolution.pdf
unable to open it ....it asks for username and passwordSolution.pdfunable to open it ....it asks for username and passwordSolution.pdf
unable to open it ....it asks for username and passwordSolution.pdfaparnacollection
 
This is called a dehydrationreaction. a) H2SO4 H20Solution.pdf
This is called a dehydrationreaction. a) H2SO4  H20Solution.pdfThis is called a dehydrationreaction. a) H2SO4  H20Solution.pdf
This is called a dehydrationreaction. a) H2SO4 H20Solution.pdfaparnacollection
 
The multiplication sign simply means that the molecules have their i.pdf
The multiplication sign simply means that the molecules have their i.pdfThe multiplication sign simply means that the molecules have their i.pdf
The multiplication sign simply means that the molecules have their i.pdfaparnacollection
 
SolutionThe variance of individual assets is measure of total ris.pdf
SolutionThe variance of individual assets is measure of total ris.pdfSolutionThe variance of individual assets is measure of total ris.pdf
SolutionThe variance of individual assets is measure of total ris.pdfaparnacollection
 
soldefnition of critical thinkingit is an intellectual process o.pdf
soldefnition of critical thinkingit is an intellectual process o.pdfsoldefnition of critical thinkingit is an intellectual process o.pdf
soldefnition of critical thinkingit is an intellectual process o.pdfaparnacollection
 
Program-a. library is importedimport java.awt.; import j.pdf
Program-a. library is importedimport java.awt.; import j.pdfProgram-a. library is importedimport java.awt.; import j.pdf
Program-a. library is importedimport java.awt.; import j.pdfaparnacollection
 
package com.test;public class Team {    private String teamId;.pdf
package com.test;public class Team {    private String teamId;.pdfpackage com.test;public class Team {    private String teamId;.pdf
package com.test;public class Team {    private String teamId;.pdfaparnacollection
 
Given below is the completed code along with comments. Output of the.pdf
Given below is the completed code along with comments. Output of the.pdfGiven below is the completed code along with comments. Output of the.pdf
Given below is the completed code along with comments. Output of the.pdfaparnacollection
 
(a) The American Institute of Certified Accountants. (AICPA)(b) Th.pdf
(a) The American Institute of Certified Accountants. (AICPA)(b) Th.pdf(a) The American Institute of Certified Accountants. (AICPA)(b) Th.pdf
(a) The American Institute of Certified Accountants. (AICPA)(b) Th.pdfaparnacollection
 
Yes. The compound is actively active. It is mainl.pdf
                     Yes. The compound is actively active. It is mainl.pdf                     Yes. The compound is actively active. It is mainl.pdf
Yes. The compound is actively active. It is mainl.pdfaparnacollection
 
The probability of A and its complement will sum to oneSolution.pdf
 The probability of A and its complement will sum to oneSolution.pdf The probability of A and its complement will sum to oneSolution.pdf
The probability of A and its complement will sum to oneSolution.pdfaparnacollection
 
H+,CN-Solution H+,CN-.pdf
 H+,CN-Solution H+,CN-.pdf H+,CN-Solution H+,CN-.pdf
H+,CN-Solution H+,CN-.pdfaparnacollection
 
1) Investment Grade Domestic Bonds As bond bears a fixed rate of i.pdf
    1) Investment Grade Domestic Bonds As bond bears a fixed rate of i.pdf    1) Investment Grade Domestic Bonds As bond bears a fixed rate of i.pdf
1) Investment Grade Domestic Bonds As bond bears a fixed rate of i.pdfaparnacollection
 
When atoms share one or more pairs of electrons t.pdf
                     When atoms share one or more pairs of electrons t.pdf                     When atoms share one or more pairs of electrons t.pdf
When atoms share one or more pairs of electrons t.pdfaparnacollection
 
This is quite simple to do. Barium sulfate is ins.pdf
                     This is quite simple to do. Barium sulfate is ins.pdf                     This is quite simple to do. Barium sulfate is ins.pdf
This is quite simple to do. Barium sulfate is ins.pdfaparnacollection
 
Step1 Cocentration of NaCl =.250 moles Step2 Mol.pdf
                     Step1 Cocentration of NaCl =.250 moles  Step2 Mol.pdf                     Step1 Cocentration of NaCl =.250 moles  Step2 Mol.pdf
Step1 Cocentration of NaCl =.250 moles Step2 Mol.pdfaparnacollection
 
Nitric acid is a strong acid... we can assume com.pdf
                     Nitric acid is a strong acid... we can assume com.pdf                     Nitric acid is a strong acid... we can assume com.pdf
Nitric acid is a strong acid... we can assume com.pdfaparnacollection
 

More from aparnacollection (20)

}Solution}.pdf
}Solution}.pdf}Solution}.pdf
}Solution}.pdf
 
What is an OS • Interface between application programs and hardwa.pdf
What is an OS • Interface between application programs and hardwa.pdfWhat is an OS • Interface between application programs and hardwa.pdf
What is an OS • Interface between application programs and hardwa.pdf
 
Using a broad definition of file(note that it doesnt count h.pdf
Using a broad definition of file(note that it doesnt count h.pdfUsing a broad definition of file(note that it doesnt count h.pdf
Using a broad definition of file(note that it doesnt count h.pdf
 
unable to open it ....it asks for username and passwordSolution.pdf
unable to open it ....it asks for username and passwordSolution.pdfunable to open it ....it asks for username and passwordSolution.pdf
unable to open it ....it asks for username and passwordSolution.pdf
 
This is called a dehydrationreaction. a) H2SO4 H20Solution.pdf
This is called a dehydrationreaction. a) H2SO4  H20Solution.pdfThis is called a dehydrationreaction. a) H2SO4  H20Solution.pdf
This is called a dehydrationreaction. a) H2SO4 H20Solution.pdf
 
The multiplication sign simply means that the molecules have their i.pdf
The multiplication sign simply means that the molecules have their i.pdfThe multiplication sign simply means that the molecules have their i.pdf
The multiplication sign simply means that the molecules have their i.pdf
 
SolutionThe variance of individual assets is measure of total ris.pdf
SolutionThe variance of individual assets is measure of total ris.pdfSolutionThe variance of individual assets is measure of total ris.pdf
SolutionThe variance of individual assets is measure of total ris.pdf
 
soldefnition of critical thinkingit is an intellectual process o.pdf
soldefnition of critical thinkingit is an intellectual process o.pdfsoldefnition of critical thinkingit is an intellectual process o.pdf
soldefnition of critical thinkingit is an intellectual process o.pdf
 
Program-a. library is importedimport java.awt.; import j.pdf
Program-a. library is importedimport java.awt.; import j.pdfProgram-a. library is importedimport java.awt.; import j.pdf
Program-a. library is importedimport java.awt.; import j.pdf
 
package com.test;public class Team {    private String teamId;.pdf
package com.test;public class Team {    private String teamId;.pdfpackage com.test;public class Team {    private String teamId;.pdf
package com.test;public class Team {    private String teamId;.pdf
 
Given below is the completed code along with comments. Output of the.pdf
Given below is the completed code along with comments. Output of the.pdfGiven below is the completed code along with comments. Output of the.pdf
Given below is the completed code along with comments. Output of the.pdf
 
(a) The American Institute of Certified Accountants. (AICPA)(b) Th.pdf
(a) The American Institute of Certified Accountants. (AICPA)(b) Th.pdf(a) The American Institute of Certified Accountants. (AICPA)(b) Th.pdf
(a) The American Institute of Certified Accountants. (AICPA)(b) Th.pdf
 
Yes. The compound is actively active. It is mainl.pdf
                     Yes. The compound is actively active. It is mainl.pdf                     Yes. The compound is actively active. It is mainl.pdf
Yes. The compound is actively active. It is mainl.pdf
 
The probability of A and its complement will sum to oneSolution.pdf
 The probability of A and its complement will sum to oneSolution.pdf The probability of A and its complement will sum to oneSolution.pdf
The probability of A and its complement will sum to oneSolution.pdf
 
H+,CN-Solution H+,CN-.pdf
 H+,CN-Solution H+,CN-.pdf H+,CN-Solution H+,CN-.pdf
H+,CN-Solution H+,CN-.pdf
 
1) Investment Grade Domestic Bonds As bond bears a fixed rate of i.pdf
    1) Investment Grade Domestic Bonds As bond bears a fixed rate of i.pdf    1) Investment Grade Domestic Bonds As bond bears a fixed rate of i.pdf
1) Investment Grade Domestic Bonds As bond bears a fixed rate of i.pdf
 
When atoms share one or more pairs of electrons t.pdf
                     When atoms share one or more pairs of electrons t.pdf                     When atoms share one or more pairs of electrons t.pdf
When atoms share one or more pairs of electrons t.pdf
 
This is quite simple to do. Barium sulfate is ins.pdf
                     This is quite simple to do. Barium sulfate is ins.pdf                     This is quite simple to do. Barium sulfate is ins.pdf
This is quite simple to do. Barium sulfate is ins.pdf
 
Step1 Cocentration of NaCl =.250 moles Step2 Mol.pdf
                     Step1 Cocentration of NaCl =.250 moles  Step2 Mol.pdf                     Step1 Cocentration of NaCl =.250 moles  Step2 Mol.pdf
Step1 Cocentration of NaCl =.250 moles Step2 Mol.pdf
 
Nitric acid is a strong acid... we can assume com.pdf
                     Nitric acid is a strong acid... we can assume com.pdf                     Nitric acid is a strong acid... we can assume com.pdf
Nitric acid is a strong acid... we can assume com.pdf
 

Recently uploaded

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...Nguyen Thanh Tu Collection
 
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjStl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjMohammed Sikander
 
An overview of the various scriptures in Hinduism
An overview of the various scriptures in HinduismAn overview of the various scriptures in Hinduism
An overview of the various scriptures in HinduismDabee Kamal
 
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of TransportBasic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of TransportDenish Jangid
 
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...Nguyen Thanh Tu Collection
 
8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital Management8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital ManagementMBA Assignment Experts
 
Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...EduSkills OECD
 
UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024Borja Sotomayor
 
Improved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio AppImproved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio AppCeline George
 
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文中 央社
 
Graduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxGraduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxneillewis46
 
How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17Celine George
 
e-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopale-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi RajagopalEADTU
 
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...Gary Wood
 
diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....Ritu480198
 
Major project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesMajor project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesAmanpreetKaur157993
 
The Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDFThe Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDFVivekanand Anglo Vedic Academy
 
MOOD STABLIZERS DRUGS.pptx
MOOD     STABLIZERS           DRUGS.pptxMOOD     STABLIZERS           DRUGS.pptx
MOOD STABLIZERS DRUGS.pptxPoojaSen20
 
Trauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesTrauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesPooky Knightsmith
 

Recently uploaded (20)

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...
 
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjStl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
 
An overview of the various scriptures in Hinduism
An overview of the various scriptures in HinduismAn overview of the various scriptures in Hinduism
An overview of the various scriptures in Hinduism
 
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of TransportBasic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
 
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
 
8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital Management8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital Management
 
Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...
 
UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024
 
Improved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio AppImproved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio App
 
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
 
Graduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxGraduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptx
 
Including Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdfIncluding Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdf
 
How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17
 
e-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopale-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopal
 
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...
 
diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....
 
Major project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesMajor project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategies
 
The Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDFThe Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDF
 
MOOD STABLIZERS DRUGS.pptx
MOOD     STABLIZERS           DRUGS.pptxMOOD     STABLIZERS           DRUGS.pptx
MOOD STABLIZERS DRUGS.pptx
 
Trauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesTrauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical Principles
 

Adding elements public void add(String element) { For fi.pdf

  • 1. // Adding elements public void add(String element) { // For first element Head is null. So, create a new node and mark it as head. // and increase numElements if(head == null){ head = new StringNode(element, null); numElements++; } else { // if not, find its place first. // then create a node and mark position link to new node // mark new node as link to positional node StringNode node = head; while(node.getLink() != null){ if(node.getData().compareTo(element) < 0){ break; } } StringNode newNode = new StringNode(element, null); newNode.setLink(node.getLink()); node.setLink(newNode); numElements++; } } // Removing elements public boolean remove(String target) { StringNode targetNode = head; boolean found = false; while (targetNode!= null && !found) { if(targetNode.getData().equalsIgnoreCase(target)) found = true;
  • 2. else targetNode = targetNode.getLink(); } if(found) { // copy the head to targetNode // and then advance head to the next node. targetNode.setData(targetNode.getLink().getData()); targetNode.setLink(targetNode.getLink()); numElements --; } return found; } Solution // Adding elements public void add(String element) { // For first element Head is null. So, create a new node and mark it as head. // and increase numElements if(head == null){ head = new StringNode(element, null); numElements++; } else { // if not, find its place first. // then create a node and mark position link to new node // mark new node as link to positional node StringNode node = head; while(node.getLink() != null){ if(node.getData().compareTo(element) < 0){ break; } } StringNode newNode = new StringNode(element, null); newNode.setLink(node.getLink());
  • 3. node.setLink(newNode); numElements++; } } // Removing elements public boolean remove(String target) { StringNode targetNode = head; boolean found = false; while (targetNode!= null && !found) { if(targetNode.getData().equalsIgnoreCase(target)) found = true; else targetNode = targetNode.getLink(); } if(found) { // copy the head to targetNode // and then advance head to the next node. targetNode.setData(targetNode.getLink().getData()); targetNode.setLink(targetNode.getLink()); numElements --; } return found; }