Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

2 import java.util.*; public class DoubleLinkedList public Node header; public Node tail; public Doublelinked List() header = null; tail = null; public void AppendToHead (int

image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
2 import java.util.*; public class DoubleLinkedList public Node header; public Node tail; public Doublelinked List() header = null; tail = null; public void AppendToHead (int newItem) Node newNode = new Node(newItem); if (header == null). header = newNode; tail = newNode; else newNode. Flink = header; header.Blink = newNode; header = newNode; public Node RemoveFromHead() Node x = header; if (header = null) 11 (header = tail) header = null; tail = null; else header = header.Flink; header.Blink = null; else System.out.println("the double linked list is empty"); return x; public void AppendToTail(int newItem) Node newlode = new Node(newItem); if (tail == null) tail = newlode; header = newNode; else new lode. Blink = tail; tail.Flink = newNode; tail = new Node; public Node RemoveFromTail() Node x = tail; if (tail != null) if (header == tail) header = null; tail = null; else tail.Blink. Flink = null; tail = tail.Blink; . else System.out.println("the double lined list is empty") return x; public Node Search(int key) Node current; current = header; while (current != null && current.item != key) current = current.Flink; return current; public void Insert(int newItem, int prekey), 107 108 Node newNode = new Node(newItem); Node current - Search(prekey); if (current == null) 109 210 System.out.println("there is no such prekey!"); if (current != null) 111 112 113 114 O AO if (current == tail) newNode.Blink = current; current.Flink = newNode; else newlode. Flink = current.Flink; newNode.Blink = current; current.Flink.Blink = newNode; current. Flink = newNode; if (newNode. Flink == null) tail = newNode; SUWNS OWNPOUW WU WU public void Delete(int key) Node p = Search (key); if (p == null) System.out.println("there is no such a key."); if (p != null) if (p != header && p != tail) p.Blink. Flink = p.Flink; p.Flink.Blink = p.Blink; if (p == header && P == tail) 49 header = null; tail = null; if (p = header && p != tail) header = null; tail = null; if (p == header && p != tail) header = header.Flink; header.Blink = null; SOSUUNTO if (p != header && p == tail) p.Blink. Flink = null; tail = p.Blink; public void PrintList() Node current = header; if (current == null) 6 268 System.out.println("The list is empty!"); return; 169 170 171 172 173 174 175 176 177 178 179 180 181 -182 183 System.out.printf("(header)%1$st ", current.item); while (!(current.Flink == null)) { current = current. Flink; if (current.Flink == null) System.out.printf("$1$s (tail)", current, item); else System.out.printf("41$s ", current item); System.out.println(" "); 2 public class Node 4 public int item; public Node link; public Node(int theItem) BBB000 item = theItem; link = null; Define a node Simple case: item is an integer class node { int item; node Flink; node Blink; BE General case: item consist of multiple elements class node { student item; + an object of node Flink; student class node Blink; 5. (15) Write a testing class that is similar to linkedListApplication class to test program Double LinkedList. Make sure that you understand each operation in the program. (Only running screenshot is required)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Structured Search For Big Data From Keywords To Key-objects

Authors: Mikhail Gilula

1st Edition

012804652X, 9780128046524

More Books

Students also viewed these Databases questions

Question

3. Write a policy statement to address these issues.

Answered: 1 week ago

Question

2. Why has the conflict escalated?

Answered: 1 week ago