SlideShare a Scribd company logo
(In java)
Create a method to delete a node at a particular position in the linked list AND
Create a method to insert a node at the tail/end of a linked list.
I have these methods that should be manipulated to achieve the methods above:
- Method for inserting a node at a particular position:
public listnodes insertAtPosition(listnodes head,int data,int position){
listnodes newnode=new listnodes(data,null);//create the newnode
listnodes previous=head;
int count=1;
while(count<=position-1) {//reach to a particular position count<position(nodeadded before)
previous=previous.link; /*if the condition in while is true that means not the
position where ypu want to add the node so go to next position*/
count++;
}
//when the condition is false, position is found
listnodes current=previous.link;
newnode.link=current;
previous.link=newnode;
return head;
}
- Method to delete the last node in a linked list:
public listnodes deletelast(listnodes head){
listnodes cur=head;
listnodes previouscur=head;
while(cur.link!=null){//traverse till the last node
previouscur=cur;
cur=cur.link;
}
previouscur.link=null;//disconnect the last node
return cur;
}
- Method to insert a node at the beginning of a linked list:
public listnodes insertnode(int data,listnodes head){
//create a new node to be added in the beginning of the linked list
listnodes newnode=new listnodes(data,null);
//link the new node to the head node
newnode.link=head;
//make the new node as the front node
head=newnode;
return head;
}

More Related Content

Similar to (In java) Create a method to delete a node at a particular position i.pdf

In Java....The methods should work as add(Node) It has to take a .pdf
In Java....The methods should work as add(Node) It has to take a .pdfIn Java....The methods should work as add(Node) It has to take a .pdf
In Java....The methods should work as add(Node) It has to take a .pdf
manjan6
 
Add delete at a position to the code and display it to the code- class.pdf
Add delete at a position to the code and display it to the code- class.pdfAdd delete at a position to the code and display it to the code- class.pdf
Add delete at a position to the code and display it to the code- class.pdf
yrajjoshi
 
Write a Java Class to Implement a Generic Linked ListYour list mus.pdf
Write a Java Class to Implement a Generic Linked ListYour list mus.pdfWrite a Java Class to Implement a Generic Linked ListYour list mus.pdf
Write a Java Class to Implement a Generic Linked ListYour list mus.pdf
rozakashif85
 
Sorted number list implementation with linked listsStep 1 Inspec.pdf
 Sorted number list implementation with linked listsStep 1 Inspec.pdf Sorted number list implementation with linked listsStep 1 Inspec.pdf
Sorted number list implementation with linked listsStep 1 Inspec.pdf
almaniaeyewear
 
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
rohit219406
 
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
 
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
fathimalinks
 
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
malavshah9013
 
Lec3-Linked list.pptx
Lec3-Linked list.pptxLec3-Linked list.pptx
Lec3-Linked list.pptx
FaheemMahmood2
 
This assignment and the next (#5) involve design and development of a.pdf
This assignment and the next (#5) involve design and development of a.pdfThis assignment and the next (#5) involve design and development of a.pdf
This assignment and the next (#5) involve design and development of a.pdf
EricvtJFraserr
 
in C++ , Design a linked list class named IntegerList to hold a seri.pdf
in C++ , Design a linked list class named IntegerList to hold a seri.pdfin C++ , Design a linked list class named IntegerList to hold a seri.pdf
in C++ , Design a linked list class named IntegerList to hold a seri.pdf
eyewaregallery
 
Write a function to merge two doubly linked lists. The input lists ha.pdf
Write a function to merge two doubly linked lists. The input lists ha.pdfWrite a function to merge two doubly linked lists. The input lists ha.pdf
Write a function to merge two doubly linked lists. The input lists ha.pdf
info706022
 

Similar to (In java) Create a method to delete a node at a particular position i.pdf (20)

In Java....The methods should work as add(Node) It has to take a .pdf
In Java....The methods should work as add(Node) It has to take a .pdfIn Java....The methods should work as add(Node) It has to take a .pdf
In Java....The methods should work as add(Node) It has to take a .pdf
 
Data Structures and Agorithm: DS 04 Linked List.pptx
Data Structures and Agorithm: DS 04 Linked List.pptxData Structures and Agorithm: DS 04 Linked List.pptx
Data Structures and Agorithm: DS 04 Linked List.pptx
 
Add delete at a position to the code and display it to the code- class.pdf
Add delete at a position to the code and display it to the code- class.pdfAdd delete at a position to the code and display it to the code- class.pdf
Add delete at a position to the code and display it to the code- class.pdf
 
Unit7 C
Unit7 CUnit7 C
Unit7 C
 
Write a Java Class to Implement a Generic Linked ListYour list mus.pdf
Write a Java Class to Implement a Generic Linked ListYour list mus.pdfWrite a Java Class to Implement a Generic Linked ListYour list mus.pdf
Write a Java Class to Implement a Generic Linked ListYour list mus.pdf
 
Sorted number list implementation with linked listsStep 1 Inspec.pdf
 Sorted number list implementation with linked listsStep 1 Inspec.pdf Sorted number list implementation with linked listsStep 1 Inspec.pdf
Sorted number list implementation with linked listsStep 1 Inspec.pdf
 
C Exam Help
C Exam Help C Exam Help
C Exam Help
 
C Homework Help
C Homework HelpC Homework Help
C Homework Help
 
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
 
The MyLinkedList class used in Listing 24.6 is a one-way directional .docx
 The MyLinkedList class used in Listing 24.6 is a one-way directional .docx The MyLinkedList class used in Listing 24.6 is a one-way directional .docx
The MyLinkedList class used in Listing 24.6 is a one-way directional .docx
 
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
 
Unit - 2.pdf
Unit - 2.pdfUnit - 2.pdf
Unit - 2.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
 
Data Structures and Agorithm: DS 05 Doubly Linked List.pptx
Data Structures and Agorithm: DS 05 Doubly Linked List.pptxData Structures and Agorithm: DS 05 Doubly Linked List.pptx
Data Structures and Agorithm: DS 05 Doubly Linked List.pptx
 
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
 
Lec3-Linked list.pptx
Lec3-Linked list.pptxLec3-Linked list.pptx
Lec3-Linked list.pptx
 
This assignment and the next (#5) involve design and development of a.pdf
This assignment and the next (#5) involve design and development of a.pdfThis assignment and the next (#5) involve design and development of a.pdf
This assignment and the next (#5) involve design and development of a.pdf
 
3.linked list
3.linked list3.linked list
3.linked list
 
in C++ , Design a linked list class named IntegerList to hold a seri.pdf
in C++ , Design a linked list class named IntegerList to hold a seri.pdfin C++ , Design a linked list class named IntegerList to hold a seri.pdf
in C++ , Design a linked list class named IntegerList to hold a seri.pdf
 
Write a function to merge two doubly linked lists. The input lists ha.pdf
Write a function to merge two doubly linked lists. The input lists ha.pdfWrite a function to merge two doubly linked lists. The input lists ha.pdf
Write a function to merge two doubly linked lists. The input lists ha.pdf
 

More from NeiltrjGreenez

- Unpovecied anal indercoarse P Poriable digital a aristant 5 HW infec.pdf
- Unpovecied anal indercoarse P Poriable digital a aristant 5 HW infec.pdf- Unpovecied anal indercoarse P Poriable digital a aristant 5 HW infec.pdf
- Unpovecied anal indercoarse P Poriable digital a aristant 5 HW infec.pdf
NeiltrjGreenez
 
(rather than herbaceous) in that the sylem often displays secondary gr.pdf
(rather than herbaceous) in that the sylem often displays secondary gr.pdf(rather than herbaceous) in that the sylem often displays secondary gr.pdf
(rather than herbaceous) in that the sylem often displays secondary gr.pdf
NeiltrjGreenez
 

More from NeiltrjGreenez (20)

- Unpovecied anal indercoarse P Poriable digital a aristant 5 HW infec.pdf
- Unpovecied anal indercoarse P Poriable digital a aristant 5 HW infec.pdf- Unpovecied anal indercoarse P Poriable digital a aristant 5 HW infec.pdf
- Unpovecied anal indercoarse P Poriable digital a aristant 5 HW infec.pdf
 
(42) How does a monopoly maintain its monopoly 433- What is a natural.pdf
(42) How does a monopoly maintain its monopoly 433- What is a natural.pdf(42) How does a monopoly maintain its monopoly 433- What is a natural.pdf
(42) How does a monopoly maintain its monopoly 433- What is a natural.pdf
 
(1) What is technology and how does it relate to a firm's PPF (or its.pdf
(1) What is technology and how does it relate to a firm's PPF (or its.pdf(1) What is technology and how does it relate to a firm's PPF (or its.pdf
(1) What is technology and how does it relate to a firm's PPF (or its.pdf
 
- Simulate the circuit of the Hexadecimal to 7-segment display decoder.pdf
- Simulate the circuit of the Hexadecimal to 7-segment display decoder.pdf- Simulate the circuit of the Hexadecimal to 7-segment display decoder.pdf
- Simulate the circuit of the Hexadecimal to 7-segment display decoder.pdf
 
- Study the sample financial statements document uploaded on Canvas- N.pdf
- Study the sample financial statements document uploaded on Canvas- N.pdf- Study the sample financial statements document uploaded on Canvas- N.pdf
- Study the sample financial statements document uploaded on Canvas- N.pdf
 
#include -sys-types-h- #include -stdio-h- #include -unistd-h- #define.pdf
#include -sys-types-h- #include -stdio-h- #include -unistd-h- #define.pdf#include -sys-types-h- #include -stdio-h- #include -unistd-h- #define.pdf
#include -sys-types-h- #include -stdio-h- #include -unistd-h- #define.pdf
 
- 1- T or F-Current liabilities are separated from long term liabiliti.pdf
- 1- T or F-Current liabilities are separated from long term liabiliti.pdf- 1- T or F-Current liabilities are separated from long term liabiliti.pdf
- 1- T or F-Current liabilities are separated from long term liabiliti.pdf
 
(Stock dividends) In the spring of 2016- the CFO of HTPL Distributing.pdf
(Stock dividends) In the spring of 2016- the CFO of HTPL Distributing.pdf(Stock dividends) In the spring of 2016- the CFO of HTPL Distributing.pdf
(Stock dividends) In the spring of 2016- the CFO of HTPL Distributing.pdf
 
(This task uses Strings-) A program that prompts the user for their pa.pdf
(This task uses Strings-) A program that prompts the user for their pa.pdf(This task uses Strings-) A program that prompts the user for their pa.pdf
(This task uses Strings-) A program that prompts the user for their pa.pdf
 
(rather than herbaceous) in that the sylem often displays secondary gr.pdf
(rather than herbaceous) in that the sylem often displays secondary gr.pdf(rather than herbaceous) in that the sylem often displays secondary gr.pdf
(rather than herbaceous) in that the sylem often displays secondary gr.pdf
 
(Python) A variable defined inside a function is a local variable- oth.pdf
(Python) A variable defined inside a function is a local variable- oth.pdf(Python) A variable defined inside a function is a local variable- oth.pdf
(Python) A variable defined inside a function is a local variable- oth.pdf
 
(Python) Create a function that can take in either a list or a diction.pdf
(Python) Create a function that can take in either a list or a diction.pdf(Python) Create a function that can take in either a list or a diction.pdf
(Python) Create a function that can take in either a list or a diction.pdf
 
(Python) Create a function that prints the number of Keys and Values.pdf
(Python)  Create a function that prints the number of Keys and Values.pdf(Python)  Create a function that prints the number of Keys and Values.pdf
(Python) Create a function that prints the number of Keys and Values.pdf
 
(Pskip)-skip.pdf
(Pskip)-skip.pdf(Pskip)-skip.pdf
(Pskip)-skip.pdf
 
(In C++) In a linked list containing student names (string) and their.pdf
(In C++) In a linked list containing student names (string) and their.pdf(In C++) In a linked list containing student names (string) and their.pdf
(In C++) In a linked list containing student names (string) and their.pdf
 
(Multiple answers) Choose all of the following that are considered ris.pdf
(Multiple answers) Choose all of the following that are considered ris.pdf(Multiple answers) Choose all of the following that are considered ris.pdf
(Multiple answers) Choose all of the following that are considered ris.pdf
 
(Multiple answers) Choose all that are risk factors for CVD- HTN famil.pdf
(Multiple answers) Choose all that are risk factors for CVD- HTN famil.pdf(Multiple answers) Choose all that are risk factors for CVD- HTN famil.pdf
(Multiple answers) Choose all that are risk factors for CVD- HTN famil.pdf
 
(ii) There were 500 insects in the total population- In this populatio.pdf
(ii) There were 500 insects in the total population- In this populatio.pdf(ii) There were 500 insects in the total population- In this populatio.pdf
(ii) There were 500 insects in the total population- In this populatio.pdf
 
(i) When the savings rate is 1-3- what is the fiscal multiplier (you c.pdf
(i) When the savings rate is 1-3- what is the fiscal multiplier (you c.pdf(i) When the savings rate is 1-3- what is the fiscal multiplier (you c.pdf
(i) When the savings rate is 1-3- what is the fiscal multiplier (you c.pdf
 
(Exercise 3-- See pages 24+40 of Interpreting earth History (A manual.pdf
(Exercise 3-- See pages 24+40 of Interpreting earth History (A manual.pdf(Exercise 3-- See pages 24+40 of Interpreting earth History (A manual.pdf
(Exercise 3-- See pages 24+40 of Interpreting earth History (A manual.pdf
 

Recently uploaded

Recently uploaded (20)

Application of Matrices in real life. Presentation on application of matrices
Application of Matrices in real life. Presentation on application of matricesApplication of Matrices in real life. Presentation on application of matrices
Application of Matrices in real life. Presentation on application of matrices
 
B.ed spl. HI pdusu exam paper-2023-24.pdf
B.ed spl. HI pdusu exam paper-2023-24.pdfB.ed spl. HI pdusu exam paper-2023-24.pdf
B.ed spl. HI pdusu exam paper-2023-24.pdf
 
Basic Civil Engineering Notes of Chapter-6, Topic- Ecosystem, Biodiversity G...
Basic Civil Engineering Notes of Chapter-6,  Topic- Ecosystem, Biodiversity G...Basic Civil Engineering Notes of Chapter-6,  Topic- Ecosystem, Biodiversity G...
Basic Civil Engineering Notes of Chapter-6, Topic- Ecosystem, Biodiversity G...
 
Benefits and Challenges of Using Open Educational Resources
Benefits and Challenges of Using Open Educational ResourcesBenefits and Challenges of Using Open Educational Resources
Benefits and Challenges of Using Open Educational Resources
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
Operations Management - Book1.p - Dr. Abdulfatah A. Salem
Operations Management - Book1.p  - Dr. Abdulfatah A. SalemOperations Management - Book1.p  - Dr. Abdulfatah A. Salem
Operations Management - Book1.p - Dr. Abdulfatah A. Salem
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
 
Basic_QTL_Marker-assisted_Selection_Sourabh.ppt
Basic_QTL_Marker-assisted_Selection_Sourabh.pptBasic_QTL_Marker-assisted_Selection_Sourabh.ppt
Basic_QTL_Marker-assisted_Selection_Sourabh.ppt
 
slides CapTechTalks Webinar May 2024 Alexander Perry.pptx
slides CapTechTalks Webinar May 2024 Alexander Perry.pptxslides CapTechTalks Webinar May 2024 Alexander Perry.pptx
slides CapTechTalks Webinar May 2024 Alexander Perry.pptx
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
 
How to the fix Attribute Error in odoo 17
How to the fix Attribute Error in odoo 17How to the fix Attribute Error in odoo 17
How to the fix Attribute Error in odoo 17
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
 
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
 
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdfDanh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
 
The Benefits and Challenges of Open Educational Resources
The Benefits and Challenges of Open Educational ResourcesThe Benefits and Challenges of Open Educational Resources
The Benefits and Challenges of Open Educational Resources
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
Pragya Champions Chalice 2024 Prelims & Finals Q/A set, General Quiz
Pragya Champions Chalice 2024 Prelims & Finals Q/A set, General QuizPragya Champions Chalice 2024 Prelims & Finals Q/A set, General Quiz
Pragya Champions Chalice 2024 Prelims & Finals Q/A set, General Quiz
 

(In java) Create a method to delete a node at a particular position i.pdf

  • 1. (In java) Create a method to delete a node at a particular position in the linked list AND Create a method to insert a node at the tail/end of a linked list. I have these methods that should be manipulated to achieve the methods above: - Method for inserting a node at a particular position: public listnodes insertAtPosition(listnodes head,int data,int position){ listnodes newnode=new listnodes(data,null);//create the newnode listnodes previous=head; int count=1; while(count<=position-1) {//reach to a particular position count<position(nodeadded before) previous=previous.link; /*if the condition in while is true that means not the position where ypu want to add the node so go to next position*/ count++; } //when the condition is false, position is found listnodes current=previous.link; newnode.link=current; previous.link=newnode; return head; } - Method to delete the last node in a linked list: public listnodes deletelast(listnodes head){ listnodes cur=head; listnodes previouscur=head; while(cur.link!=null){//traverse till the last node previouscur=cur; cur=cur.link; } previouscur.link=null;//disconnect the last node return cur; } - Method to insert a node at the beginning of a linked list:
  • 2. public listnodes insertnode(int data,listnodes head){ //create a new node to be added in the beginning of the linked list listnodes newnode=new listnodes(data,null); //link the new node to the head node newnode.link=head; //make the new node as the front node head=newnode; return head; }