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);

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

 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); } }

Expert Solution
steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY