SlideShare a Scribd company logo
1 of 4
Download to read offline
Create your own Linked list from scratch (singly linked list).
Solution
Hi Friend, You have not mentioned about programming language.
Please try to mention all details.
I have implemented LinkedList in Java.
class NodeList {
int data;
NodeList next;
public NodeList(int data) {
this.data = data;
next = null;
}
}
public class LinkedList {
private NodeList head, tail;
private int size;
public LinkedList() {
head = null;
size = 0;
tail = null;
}
public void append(int data) {
// if list is null
if(head == null){
head = new NodeList(data);
tail = head;
return;
}
NodeList newNode = new NodeList(data);
tail.next = newNode;
tail = newNode;
}
public void deleteLast(){
if(head == null){
System.out.println("List is empty");
return ;
}
if(head.next == null){ // only one node
head = tail = null;
}
NodeList temp = head;
while(temp.next != tail)
temp = temp.next;
temp.next = null;
tail = temp;
}
public void deleteNthNode(int n){
if(size < n){
System.out.println("Less than "+n+"node in list");
return;
}
if(n==1){// delete first element
head = head.next;
return;
}
if(size == n){ // delete last
deleteLast();
return;
}
NodeList temp = head;
for(int i=1; i size + 1){
System.out.println("Total number of elements in list is "+size);
return;
}
NodeList newNode = new NodeList(data);
if(n==1){//inserting at first
newNode.next = head;
head = newNode;
if(tail == null)
tail = head;
}
else if(size+1 == n){ // inserting at last
tail.next = newNode;
tail = newNode;
}
else{
NodeList temp = head;
for(int i=1; i");
else
System.out.println(temp.data);
temp = temp.next;
}
System.out.println();
}
}
####################
public class TestLinkedList {
public static void main(String[] args) {
LinkedList list = new LinkedList();
list.append(1);
list.append(2);
list.append(3);
list.display();
list.insertAfter(4, 1);
list.display();
}
}
/*
Sample run:
1-->2-->3
4-->1-->2-->3
*/

More Related Content

Similar to Create your own Linked list from scratch (singly linked list).So.pdf

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.pdfeyewaregallery
 
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.pdfarchgeetsenterprises
 
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.pdfyrajjoshi
 
In this assignment you will implement insert() method for a singly l.pdf
In this assignment you will implement insert() method for a singly l.pdfIn this assignment you will implement insert() method for a singly l.pdf
In this assignment you will implement insert() method for a singly l.pdffantasiatheoutofthef
 
Solve using Java programming language- ----------------------------.pdf
Solve using Java programming language-   ----------------------------.pdfSolve using Java programming language-   ----------------------------.pdf
Solve using Java programming language- ----------------------------.pdfaksahnan
 
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.pdfclarityvision
 
Lec-4_Linked-List (1).pdf
Lec-4_Linked-List (1).pdfLec-4_Linked-List (1).pdf
Lec-4_Linked-List (1).pdfKylaMaeGarcia1
 
Write a program to implement below operations with both singly and d.pdf
Write a program to implement below operations with both singly and d.pdfWrite a program to implement below operations with both singly and d.pdf
Write a program to implement below operations with both singly and d.pdfthangarajarivukadal
 
Implement the additional 5 methods as indicated in the LinkedList fi.pdf
Implement the additional 5 methods as indicated in the LinkedList fi.pdfImplement the additional 5 methods as indicated in the LinkedList fi.pdf
Implement the additional 5 methods as indicated in the LinkedList fi.pdffootstatus
 
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.pdffootstatus
 
Help please!!(Include your modified DList.java source code file in.pdf
Help please!!(Include your modified DList.java source code file in.pdfHelp please!!(Include your modified DList.java source code file in.pdf
Help please!!(Include your modified DList.java source code file in.pdfjyothimuppasani1
 
Using Java programming language solve the followingSLL CLASS.pdf
Using Java programming language solve the followingSLL CLASS.pdfUsing Java programming language solve the followingSLL CLASS.pdf
Using Java programming language solve the followingSLL CLASS.pdfadonisjpr
 
#include sstream #include linkylist.h #include iostream.pdf
#include sstream #include linkylist.h #include iostream.pdf#include sstream #include linkylist.h #include iostream.pdf
#include sstream #include linkylist.h #include iostream.pdfaravlitraders2012
 
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.pdfsauravmanwanicp
 
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
 
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..pdfferoz544
 
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
 
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
 
linked List.docx vhjgvjhvgjhjhbbjkhkjhkjh
linked List.docx vhjgvjhvgjhjhbbjkhkjhkjhlinked List.docx vhjgvjhvgjhjhbbjkhkjhkjh
linked List.docx vhjgvjhvgjhjhbbjkhkjhkjhvasavim9
 
In Java write a menu driven program that implements the following li.pdf
In Java write a menu driven program that implements the following li.pdfIn Java write a menu driven program that implements the following li.pdf
In Java write a menu driven program that implements the following li.pdfarihantelehyb
 

Similar to Create your own Linked list from scratch (singly linked list).So.pdf (20)

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
 
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
 
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
 
In this assignment you will implement insert() method for a singly l.pdf
In this assignment you will implement insert() method for a singly l.pdfIn this assignment you will implement insert() method for a singly l.pdf
In this assignment you will implement insert() method for a singly l.pdf
 
Solve using Java programming language- ----------------------------.pdf
Solve using Java programming language-   ----------------------------.pdfSolve using Java programming language-   ----------------------------.pdf
Solve using Java programming language- ----------------------------.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
 
Lec-4_Linked-List (1).pdf
Lec-4_Linked-List (1).pdfLec-4_Linked-List (1).pdf
Lec-4_Linked-List (1).pdf
 
Write a program to implement below operations with both singly and d.pdf
Write a program to implement below operations with both singly and d.pdfWrite a program to implement below operations with both singly and d.pdf
Write a program to implement below operations with both singly and d.pdf
 
Implement the additional 5 methods as indicated in the LinkedList fi.pdf
Implement the additional 5 methods as indicated in the LinkedList fi.pdfImplement the additional 5 methods as indicated in the LinkedList fi.pdf
Implement the additional 5 methods as indicated in the LinkedList fi.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
 
Help please!!(Include your modified DList.java source code file in.pdf
Help please!!(Include your modified DList.java source code file in.pdfHelp please!!(Include your modified DList.java source code file in.pdf
Help please!!(Include your modified DList.java source code file in.pdf
 
Using Java programming language solve the followingSLL CLASS.pdf
Using Java programming language solve the followingSLL CLASS.pdfUsing Java programming language solve the followingSLL CLASS.pdf
Using Java programming language solve the followingSLL CLASS.pdf
 
#include sstream #include linkylist.h #include iostream.pdf
#include sstream #include linkylist.h #include iostream.pdf#include sstream #include linkylist.h #include iostream.pdf
#include sstream #include linkylist.h #include iostream.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
 
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
 
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
 
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
 
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
 
linked List.docx vhjgvjhvgjhjhbbjkhkjhkjh
linked List.docx vhjgvjhvgjhjhbbjkhkjhkjhlinked List.docx vhjgvjhvgjhjhbbjkhkjhkjh
linked List.docx vhjgvjhvgjhjhbbjkhkjhkjh
 
In Java write a menu driven program that implements the following li.pdf
In Java write a menu driven program that implements the following li.pdfIn Java write a menu driven program that implements the following li.pdf
In Java write a menu driven program that implements the following li.pdf
 

More from arumugambags

Case 2-A Work–Life Balance Answer the following questions at the bo.pdf
Case 2-A Work–Life Balance Answer the following questions at the bo.pdfCase 2-A Work–Life Balance Answer the following questions at the bo.pdf
Case 2-A Work–Life Balance Answer the following questions at the bo.pdfarumugambags
 
C++ Write a function which prompts the user for a number and return.pdf
C++ Write a function which prompts the user for a number and return.pdfC++ Write a function which prompts the user for a number and return.pdf
C++ Write a function which prompts the user for a number and return.pdfarumugambags
 
Any ideas why this isnt being recognized as a class. Its conside.pdf
Any ideas why this isnt being recognized as a class. Its conside.pdfAny ideas why this isnt being recognized as a class. Its conside.pdf
Any ideas why this isnt being recognized as a class. Its conside.pdfarumugambags
 
actice edF sophy i does As a Make perspective, the HR perspective, .pdf
actice edF sophy i does As a Make perspective, the HR perspective, .pdfactice edF sophy i does As a Make perspective, the HR perspective, .pdf
actice edF sophy i does As a Make perspective, the HR perspective, .pdfarumugambags
 
why is it important in everyday life to monitor water levels in orga.pdf
why is it important in everyday life to monitor water levels in orga.pdfwhy is it important in everyday life to monitor water levels in orga.pdf
why is it important in everyday life to monitor water levels in orga.pdfarumugambags
 
Which system performs better using OFDM to service two different us.pdf
Which system performs better using OFDM to service two different us.pdfWhich system performs better using OFDM to service two different us.pdf
Which system performs better using OFDM to service two different us.pdfarumugambags
 
Which of the following statements is not truea.Every wallpaper pa.pdf
Which of the following statements is not truea.Every wallpaper pa.pdfWhich of the following statements is not truea.Every wallpaper pa.pdf
Which of the following statements is not truea.Every wallpaper pa.pdfarumugambags
 
Which of the following demonstrates ectothermic behaviorQuestion .pdf
Which of the following demonstrates ectothermic behaviorQuestion .pdfWhich of the following demonstrates ectothermic behaviorQuestion .pdf
Which of the following demonstrates ectothermic behaviorQuestion .pdfarumugambags
 
What role does childrens play have in motor delopment What r.pdf
What role does childrens play have in motor delopment What r.pdfWhat role does childrens play have in motor delopment What r.pdf
What role does childrens play have in motor delopment What r.pdfarumugambags
 
What questions are descriptive studies designed to answerSoluti.pdf
What questions are descriptive studies designed to answerSoluti.pdfWhat questions are descriptive studies designed to answerSoluti.pdf
What questions are descriptive studies designed to answerSoluti.pdfarumugambags
 
What is a current liability Distinguish between a current liability.pdf
What is a current liability Distinguish between a current liability.pdfWhat is a current liability Distinguish between a current liability.pdf
What is a current liability Distinguish between a current liability.pdfarumugambags
 
What are some of the evolutionary evidence that suggests we evolv.pdf
What are some of the evolutionary evidence that suggests we evolv.pdfWhat are some of the evolutionary evidence that suggests we evolv.pdf
What are some of the evolutionary evidence that suggests we evolv.pdfarumugambags
 
What are the five signs of tissue injurySolutionAnsThe fiv.pdf
What are the five signs of tissue injurySolutionAnsThe fiv.pdfWhat are the five signs of tissue injurySolutionAnsThe fiv.pdf
What are the five signs of tissue injurySolutionAnsThe fiv.pdfarumugambags
 
We regularly allow beer companies to advertise across various mass m.pdf
We regularly allow beer companies to advertise across various mass m.pdfWe regularly allow beer companies to advertise across various mass m.pdf
We regularly allow beer companies to advertise across various mass m.pdfarumugambags
 
A father and his son were watching Jeopardy on TV. The son, a compute.pdf
A father and his son were watching Jeopardy on TV. The son, a compute.pdfA father and his son were watching Jeopardy on TV. The son, a compute.pdf
A father and his son were watching Jeopardy on TV. The son, a compute.pdfarumugambags
 
The purchase of inventory would be considered aA.cash outflow fr.pdf
The purchase of inventory would be considered aA.cash outflow fr.pdfThe purchase of inventory would be considered aA.cash outflow fr.pdf
The purchase of inventory would be considered aA.cash outflow fr.pdfarumugambags
 
The mission of University is the transformation of the whole person .pdf
The mission of University is the transformation of the whole person .pdfThe mission of University is the transformation of the whole person .pdf
The mission of University is the transformation of the whole person .pdfarumugambags
 
The firm is Tesla Motors1.Based on information in the annual repor.pdf
The firm is Tesla Motors1.Based on information in the annual repor.pdfThe firm is Tesla Motors1.Based on information in the annual repor.pdf
The firm is Tesla Motors1.Based on information in the annual repor.pdfarumugambags
 
4 A piece of lead metal was added to an aqueous solution of copper(I.pdf
4 A piece of lead metal was added to an aqueous solution of copper(I.pdf4 A piece of lead metal was added to an aqueous solution of copper(I.pdf
4 A piece of lead metal was added to an aqueous solution of copper(I.pdfarumugambags
 
Researchers are interested in studying whether personality is relate.pdf
Researchers are interested in studying whether personality is relate.pdfResearchers are interested in studying whether personality is relate.pdf
Researchers are interested in studying whether personality is relate.pdfarumugambags
 

More from arumugambags (20)

Case 2-A Work–Life Balance Answer the following questions at the bo.pdf
Case 2-A Work–Life Balance Answer the following questions at the bo.pdfCase 2-A Work–Life Balance Answer the following questions at the bo.pdf
Case 2-A Work–Life Balance Answer the following questions at the bo.pdf
 
C++ Write a function which prompts the user for a number and return.pdf
C++ Write a function which prompts the user for a number and return.pdfC++ Write a function which prompts the user for a number and return.pdf
C++ Write a function which prompts the user for a number and return.pdf
 
Any ideas why this isnt being recognized as a class. Its conside.pdf
Any ideas why this isnt being recognized as a class. Its conside.pdfAny ideas why this isnt being recognized as a class. Its conside.pdf
Any ideas why this isnt being recognized as a class. Its conside.pdf
 
actice edF sophy i does As a Make perspective, the HR perspective, .pdf
actice edF sophy i does As a Make perspective, the HR perspective, .pdfactice edF sophy i does As a Make perspective, the HR perspective, .pdf
actice edF sophy i does As a Make perspective, the HR perspective, .pdf
 
why is it important in everyday life to monitor water levels in orga.pdf
why is it important in everyday life to monitor water levels in orga.pdfwhy is it important in everyday life to monitor water levels in orga.pdf
why is it important in everyday life to monitor water levels in orga.pdf
 
Which system performs better using OFDM to service two different us.pdf
Which system performs better using OFDM to service two different us.pdfWhich system performs better using OFDM to service two different us.pdf
Which system performs better using OFDM to service two different us.pdf
 
Which of the following statements is not truea.Every wallpaper pa.pdf
Which of the following statements is not truea.Every wallpaper pa.pdfWhich of the following statements is not truea.Every wallpaper pa.pdf
Which of the following statements is not truea.Every wallpaper pa.pdf
 
Which of the following demonstrates ectothermic behaviorQuestion .pdf
Which of the following demonstrates ectothermic behaviorQuestion .pdfWhich of the following demonstrates ectothermic behaviorQuestion .pdf
Which of the following demonstrates ectothermic behaviorQuestion .pdf
 
What role does childrens play have in motor delopment What r.pdf
What role does childrens play have in motor delopment What r.pdfWhat role does childrens play have in motor delopment What r.pdf
What role does childrens play have in motor delopment What r.pdf
 
What questions are descriptive studies designed to answerSoluti.pdf
What questions are descriptive studies designed to answerSoluti.pdfWhat questions are descriptive studies designed to answerSoluti.pdf
What questions are descriptive studies designed to answerSoluti.pdf
 
What is a current liability Distinguish between a current liability.pdf
What is a current liability Distinguish between a current liability.pdfWhat is a current liability Distinguish between a current liability.pdf
What is a current liability Distinguish between a current liability.pdf
 
What are some of the evolutionary evidence that suggests we evolv.pdf
What are some of the evolutionary evidence that suggests we evolv.pdfWhat are some of the evolutionary evidence that suggests we evolv.pdf
What are some of the evolutionary evidence that suggests we evolv.pdf
 
What are the five signs of tissue injurySolutionAnsThe fiv.pdf
What are the five signs of tissue injurySolutionAnsThe fiv.pdfWhat are the five signs of tissue injurySolutionAnsThe fiv.pdf
What are the five signs of tissue injurySolutionAnsThe fiv.pdf
 
We regularly allow beer companies to advertise across various mass m.pdf
We regularly allow beer companies to advertise across various mass m.pdfWe regularly allow beer companies to advertise across various mass m.pdf
We regularly allow beer companies to advertise across various mass m.pdf
 
A father and his son were watching Jeopardy on TV. The son, a compute.pdf
A father and his son were watching Jeopardy on TV. The son, a compute.pdfA father and his son were watching Jeopardy on TV. The son, a compute.pdf
A father and his son were watching Jeopardy on TV. The son, a compute.pdf
 
The purchase of inventory would be considered aA.cash outflow fr.pdf
The purchase of inventory would be considered aA.cash outflow fr.pdfThe purchase of inventory would be considered aA.cash outflow fr.pdf
The purchase of inventory would be considered aA.cash outflow fr.pdf
 
The mission of University is the transformation of the whole person .pdf
The mission of University is the transformation of the whole person .pdfThe mission of University is the transformation of the whole person .pdf
The mission of University is the transformation of the whole person .pdf
 
The firm is Tesla Motors1.Based on information in the annual repor.pdf
The firm is Tesla Motors1.Based on information in the annual repor.pdfThe firm is Tesla Motors1.Based on information in the annual repor.pdf
The firm is Tesla Motors1.Based on information in the annual repor.pdf
 
4 A piece of lead metal was added to an aqueous solution of copper(I.pdf
4 A piece of lead metal was added to an aqueous solution of copper(I.pdf4 A piece of lead metal was added to an aqueous solution of copper(I.pdf
4 A piece of lead metal was added to an aqueous solution of copper(I.pdf
 
Researchers are interested in studying whether personality is relate.pdf
Researchers are interested in studying whether personality is relate.pdfResearchers are interested in studying whether personality is relate.pdf
Researchers are interested in studying whether personality is relate.pdf
 

Recently uploaded

How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701bronxfugly43
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural ResourcesEnergy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural ResourcesShubhangi Sonawane
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 

Recently uploaded (20)

How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural ResourcesEnergy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 

Create your own Linked list from scratch (singly linked list).So.pdf

  • 1. Create your own Linked list from scratch (singly linked list). Solution Hi Friend, You have not mentioned about programming language. Please try to mention all details. I have implemented LinkedList in Java. class NodeList { int data; NodeList next; public NodeList(int data) { this.data = data; next = null; } } public class LinkedList { private NodeList head, tail; private int size; public LinkedList() { head = null; size = 0; tail = null; } public void append(int data) { // if list is null if(head == null){ head = new NodeList(data); tail = head; return; } NodeList newNode = new NodeList(data); tail.next = newNode; tail = newNode; }
  • 2. public void deleteLast(){ if(head == null){ System.out.println("List is empty"); return ; } if(head.next == null){ // only one node head = tail = null; } NodeList temp = head; while(temp.next != tail) temp = temp.next; temp.next = null; tail = temp; } public void deleteNthNode(int n){ if(size < n){ System.out.println("Less than "+n+"node in list"); return; } if(n==1){// delete first element head = head.next; return; } if(size == n){ // delete last deleteLast(); return; } NodeList temp = head;
  • 3. for(int i=1; i size + 1){ System.out.println("Total number of elements in list is "+size); return; } NodeList newNode = new NodeList(data); if(n==1){//inserting at first newNode.next = head; head = newNode; if(tail == null) tail = head; } else if(size+1 == n){ // inserting at last tail.next = newNode; tail = newNode; } else{ NodeList temp = head; for(int i=1; i"); else System.out.println(temp.data); temp = temp.next; } System.out.println(); } } #################### public class TestLinkedList { public static void main(String[] args) { LinkedList list = new LinkedList(); list.append(1); list.append(2);