Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hi can you help me answer the following Data Structure and Algorithm Question using Java with step by step detailed solution and explanation? Thank you

Hi can you help me answer the following Data Structure and Algorithm Question using Java with step by step detailed solution and explanation? Thank you very much!

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

4. Code for implementing a circular doubly-linked list is given below: public interface Iterator public boolean hasNext(); public boolean hasPrevious (); public int next () throws Exception; // move iterator to the next position, // then returns the value at that position. public int previous() throws Exception; // return the value at current position, // then move the iterator back one position. public void set(int value); public class DListIterator implements Iterator { DListNode currentNode; // interested position DListIterator(DListNode theNode) { currentNodetheNode; public boolean hasNext()t // always true for circular list return currentNode.nextNode != null; public boolean hasPrevious() f // always true for circular list return currentNode.previousNode !- null; public int next () throws Exception { // Throw exception if the next data // does not exist. if (!hasNext()) throw new NoSuchElementException(); currentNodecurrentNode.nextNode; return currentNode.data public int previous() throws Exception if (!hasPrevious ()) throw new NoSuchElementException(); int data-currentNode.data currentNode currentNode.previousNode; return data; public void set(int value) { currentNode.data = value; class DListNode { DListNode (int data) { this(data, nul1, null); DListNode (int theElement, DListNode n, DListNode p) data-theElement; nextNode = n; previousNodep; // Friendly data; accessible by other package routines int data DListNode nextNode, previousNode; public class CDLinkedList f DListNode header; int size; static final int HEADERVALUE = -9999999; public CDLinkedList() 1 size = 0; headernew DListNode(HEADERVALUE); makeEmpty);/ecessary, otherwise next/previous node will be null public boolean isEmpty) return header.nextNodeheader; public boolean isFull() { return false; public void makeEmpty() { header.nextNode = header; header.previouSNode header; // put in new data after the position of p. public void insert(int value, Iterator p) throws Exception { if (p == null II ! (p instanceof DLstterator)) throw new Exception() DListIterator p2(DListIterator) p; if (p2.currentNodenull) throw new Exception); Need to be filled! See question 4 a) // return position number of value found in the list. // otherwise, return -1 public int find(int value) throws Exception iterator itr new DLstiterator(header); int index - -1; while (itr.hasNext()) int v- itr.next) index++ DListiterator tr2 (DListiterator) itr; if (itr2.currentNode == header) return 1; if (vvalue) return index; // return the position of value. return-1; // return data stored at kth position public int findKth(int kthPosition) throws Exception if (kthPosition

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

Time Series Databases New Ways To Store And Access Data

Authors: Ted Dunning, Ellen Friedman

1st Edition

1491914726, 978-1491914724

More Books

Students also viewed these Databases questions