// define ListNode elements specific for this type of list, indicating current, previous and next // consider head as name for previous node, and tail for the next one. private ListNode head; private ListNode current; private ListNode tail; // default constructor public DoublyLinkedList() { //*** Task #1: implement a default constructor here, initializing the nodes to null } // method that calculates the length of the list public int length() {

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter17: Linked Lists
Section: Chapter Questions
Problem 13PE
icon
Related questions
Question
7.
ASK class DoublyLinkedList<E>

{
// define ListNode elements specific for this type of list, indicating current, previous and next
// consider head as name for previous node, and tail for the next one.
private ListNode<E> head;
private ListNode<E> current;
private ListNode<E> tail;

// default constructor
public DoublyLinkedList()
{
//*** Task #1: implement a default constructor here, initializing the nodes to null

}

// method that calculates the length of the list
public int length()
{
//*** Task #2: implement the method navigating through the list until you run out of elements

}

// method that adds a node at the beginning of the list
public void addANodeToStart(E addData)
{
//*** Task #3: implement this method, taking into consideration that the head will be replaced by a new node. You may want to use a temporary variable

}

// accessor method that gets data at current node
public E getDataAtCurrent()
{
//*** Task #4: implement this method making sure to take into account the situation when
// there current doesn't point to any data (is null)

}

// method that sets the current node in the beginning, reseting the iteration
public void resetIteration()
{
//*** Task #5: implement the body of the method
}

// method that checks if there is more to interate in the list
public boolean moreToIterate()
{
//*** Task #6: implement the body of the method
}

// method that moves the node to the next position, if possible
public void goToNext()
{
//*** Task #7: implement the method taking into account the situation when the list is empty
// check if there are other instances when the move is not possible.

}

// method that resets the reverse iteration, setting the current node to the last one
public void resetIterationReverse()
{
//*** Task #8: implement the body of the method
}

// method that facilitates the move in the reverse directions, redirecting the node to previous
public void goToPrevious()
{
//*** Task #9: implement this method in a similar way the goToNext() method
// make sure to have the right links for the reverse navigations
}

/*
Method that inserts node with newData after the current node.
Note: The current node is the same after invocation as it is before invocation.
Should not be used with an empty list.
Should not be used when the current node has iterated past the entire list.
*/
public void insertNodeAfterCurrent(E newData)
{
//*** Task #10: implement this method, making sure to observe the ideas noted above
}

/*
Method that deletes the current node. After the invocation,
the current node is the node after the
deleted node or null if there is no next node.
*/
public void deleteCurrentNode()
{
//*** Task #11: implement this method, making sure to observe the ideas noted above
}

// method that deletes the head node.
public void deleteHeadNode()
{
//*** Task #12: implement this method

}

// Searches list for element containing target data.
// If target is found, current is set to point at it,
// and the function returns true.
// If target is not found, current is set to null
// and the function returns false.
public boolean findInList(E target)
{
//*** Task #13: implement this method, making sure to observe the ideas noted above

}

public boolean onList(E target)
{
//*** Task #14: implement this method
}

private ListNode<E> Find(E target)
{
//*** Task #15: implement this method
}

// meethod that displays the list
public void showList()
{
//*** Task #16: irrespective of navigation through the list, the display remains the same
// start from the head and move through the list to show all elements.
}

// Method useful during testing and debugging, that allows control over the nodes.
public void showListState()
{
System.out.println("Head: " + (head == null ? "null" : head.data)
+ " Current: " + (current == null ? "null" : current.data)
+ " Tail: " + (tail == null ? "null" : tail.data)
+ " " + length() + " items");
}

 

// inner class for ListNode
public class ListNode<E>
{
// instance variables
private E data;
private ListNode<E> link;
private ListNode<E> previous;
// constructor - default
public ListNode()
{
//*** Task #17: implement this constructor
}
// constructor, fully defining the list
public ListNode(E newData, ListNode<E> linkValue, ListNode<E> previousValue)
{
//*** Task #18: implement this constructor
}
// mutator for data
public void setData(E newData)
{
//*** Task #19: implement this method
}
// accessor for data
public E getData()
{
//*** Task #20: implement this method
}
// mutator for the node
public void setLink(ListNode<E> newLink)
{
//*** Task #21: implement this method
}
// mutator for the previous node
public void setPrevious(ListNode<E> newPrevious)
{
//*** Task #22: implement this method
}
// accessor for the current node
public ListNode<E> getLink()
{
//*** Task #23: implement this method
}
// accessor for the previous node
public ListNode<E> getPrevious()
{
//*** Task #24: implement this method
}
}
}.

 

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Operations of Linked List
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning