I want to make this code to Double linked list class Node{ int data; Node next; public Node(int d) { this(d,null); } public Node(int d,Node n) { data=d; next=n; } } public class List { private Node head; public List() { head=null; } public void addBegining(int d) { Node n=new Node(d); if(head==null) { head=n; }else { n.next=head; head=n; } } public void addEnd(int d) { if(head==null) { head=new Node(d); }else { Node tmp=head; while(tmp.next!=null) tmp=tmp.next; tmp.next=new Node(d); } } public String toString() { Node tmp=head; String ans=""; while(tmp!=null) { ans+=tmp.data+"-->"; tmp=tmp.next; } return ans; } public void deleteBegining() { if (head!=null) { head=head.next; } } public void deleteEnd() { Node tmp=head; Node prev = null; while (tmp.next!=null) { prev=tmp; tmp=tmp.next; } prev.next=null; } public boolean contains(int d) { Node tmp=head; while(tmp!=null) { if (tmp.data==d) return true; tmp=tmp.next; } return false; } public void remove(int d) { Node tmp=head; Node prev=null; while(tmp!=null && tmp.data!=d) { prev=tmp; tmp=tmp.next; } if(tmp!=null) prev.next=tmp.next; } public static void main(String[] args) { // TODO Auto-generated method stub List L=new List(); L.addBegining(10); L.addBegining(20); L.addBegining(5); L.addEnd(50); L.addEnd(100); L.addBegining(1); System.out.println(L); L.deleteBegining(); System.out.println(L); L.deleteEnd(); System.out.println(L); System.out.println(L.contains(10)); System.out.println(L.contains(100)); L.remove(1000);
I want to make this code to Double linked list
class Node{ int data; Node next; public Node(int d) { this(d,null); } public Node(int d,Node n) { data=d; next=n; } } public class List { private Node head; public List() { head=null; } public void addBegining(int d) { Node n=new Node(d); if(head==null) { head=n; }else { n.next=head; head=n; } } public void addEnd(int d) { if(head==null) { head=new Node(d); }else { Node tmp=head; while(tmp.next!=null) tmp=tmp.next; tmp.next=new Node(d); } } public String toString() { Node tmp=head; String ans=""; while(tmp!=null) { ans+=tmp.data+"-->"; tmp=tmp.next; } return ans; } public void deleteBegining() { if (head!=null) { head=head.next; } } public void deleteEnd() { Node tmp=head; Node prev = null; while (tmp.next!=null) { prev=tmp; tmp=tmp.next; } prev.next=null; } public boolean contains(int d) { Node tmp=head; while(tmp!=null) { if (tmp.data==d) return true; tmp=tmp.next; } return false; } public void remove(int d) { Node tmp=head; Node prev=null; while(tmp!=null && tmp.data!=d) { prev=tmp; tmp=tmp.next; } if(tmp!=null) prev.next=tmp.next; } public static void main(String[] args) { // TODO Auto-generated method stub List L=new List(); L.addBegining(10); L.addBegining(20); L.addBegining(5); L.addEnd(50); L.addEnd(100); L.addBegining(1); System.out.println(L); L.deleteBegining(); System.out.println(L); L.deleteEnd(); System.out.println(L); System.out.println(L.contains(10)); System.out.println(L.contains(100)); L.remove(1000); System.out.println(L); } }
![](/static/compass_v2/shared-icons/check-mark.png)
Step by step
Solved in 4 steps with 2 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
![Concepts of Database Management](https://www.bartleby.com/isbn_cover_images/9781337093422/9781337093422_smallCoverImage.gif)
![Prelude to Programming](https://www.bartleby.com/isbn_cover_images/9780133750423/9780133750423_smallCoverImage.jpg)
![Sc Business Data Communications and Networking, T…](https://www.bartleby.com/isbn_cover_images/9781119368830/9781119368830_smallCoverImage.gif)