Data Structures and Algorithms in Java
6th Edition
ISBN: 9781118771334
Author: Michael T. Goodrich
Publisher: WILEY
expand_more
expand_more
format_list_bulleted
Question
Chapter 3, Problem 33C
Program Plan Intro
Initial consideration:
While the circularly liked list implementation has to be provided using inheritance in such a way that a DoublyLinkedList class inherits from the existing CircularlyLinkedList, and the DoublyLinkedList.Node nested class inherits from CircularlyLinkedList.Node.
The following consideration has to be made before implementation:
- A circular version of a doubly linked list has to be implemented that is not having any sentinels that can generally supports the public behaviors of the original and new update methods.
- The implemented circular doubly linked list should have method called rotate() which is used to rotate the linked list counter clockwise and rotateBackward() method that can support the public behaviors of the linked list.
- There is no need to use the sentinel nodes which are more generally useful with linked list implementation that helps to maintain the reference of all nodes of a doubly linked list.
- The node in the circular version of doubly linked list maintains two references with the previous and the next node in the doubly linked list.
Doubly-linked list:
- Doubly-linked list is a kind of data structure in which every node in the list has two link pointers where one link is pointing to previous node and the link will point to the next node in the list.
- The first node in the linked list generally points to a Null pointer and the next link of the last node in the linked list is pointing to the Null.
CircularlyLinkedList:
- Circular Linked List is also a kind of data structure where all the nodes in the list are in the formed of a circular fashion.
- The circular pattern can be a singly or doubly linked list. Unlike doubly linked list there is no Null pointer in the circular linked list. The nodes are added and removed based on the constant time factor.
- The main advantage of circular linked list is the ability to traverse the nodes of the linked list.
Inheritance:
- In object-oriented programming (OOP) inheritance is a procedure to create new class from an existing class which is known as base class or super class and the inherited class is known as derived class or sub class and the new class will inherits all the properties of the existing parent class.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
4. Suppose our MyLinkedList class represented a doubly linked list, where each Node is
implemented as follows:
private class Node {
Node prev, next;
E element;
}
public Node (E element) {
}
this.element = element;
Each Node has a reference to the previous Node as well as to the next Node in the list. MINIMALLY
modify the add(int index, E element) method below to work properly with the doubly linked
Nodes, and highlight or underline your changes.
Programming Exercise 8 asks you to redefine the class to implement the nodes of a linked list so that the instance variables are private. Therefore, the class linkedListType and its derived classes unorderedLinkedList and orderedLinkedList can no longer directly access the instance variables of the class nodeType. Rewrite the definitions of these classes so that these classes use the member functions of the class nodeType to access the info and link fields of a node. Also write programs to test various operations of the classes unorderedLinkedList and orderedLinkedList.
template <class Type>class nodeType{public:const nodeType<Type>& operator=(const nodeType<Type>&);//Overload the assignment operator.void setInfo(const Type& elem);//Function to set the info of the node.//Postcondition: info = elem;Type getInfo() const;//Function to return the info of the node.//Postcondition: The value of info is returned.void setLink(nodeType<Type>…
Use the ArrayList class
Add and remove objects from an ArrayList
Protect from index errors when removing
Practice with input loop
Details:
This homework is for you to get practice adding and removing objects from an ArrayList.
The Voter class was used to create instances of Voters which held their name and a voter identification number as instance variables, and the number of instances created as a static variable. This was the class diagram:
The constructor takes a string, passed to the parameter n, which is the name of the voter and which should be assigned to the name instance variable. Every time a new voter is created, the static variable nVoters should be incremented. Also, every time a new voter is created, a new voterID should be constructed by concatenating the string “HI” with the value of nVoters and the length of the name. For example, if the second voter is named “Clark Kent”, then the voterID should be “HI210” because 2 is the value of nVoters and 10 is the number…
Chapter 3 Solutions
Data Structures and Algorithms in Java
Ch. 3 - Prob. 1RCh. 3 - Write a Java method that repeatedly selects and...Ch. 3 - Prob. 3RCh. 3 - The TicTacToe class of Code Fragments 3.9 and 3.10...Ch. 3 - Prob. 5RCh. 3 - Prob. 6RCh. 3 - Prob. 7RCh. 3 - Prob. 8RCh. 3 - Prob. 9RCh. 3 - Prob. 10R
Ch. 3 - Prob. 11RCh. 3 - Prob. 12RCh. 3 - Prob. 13RCh. 3 - Prob. 14RCh. 3 - Prob. 15RCh. 3 - Prob. 16RCh. 3 - Prob. 17CCh. 3 - Prob. 18CCh. 3 - Prob. 19CCh. 3 - Give examples of values for a and b in the...Ch. 3 - Suppose you are given an array, A, containing 100...Ch. 3 - Write a method, shuffle(A), that rearranges the...Ch. 3 - Suppose you are designing a multiplayer game that...Ch. 3 - Write a Java method that takes two...Ch. 3 - Prob. 25CCh. 3 - Prob. 26CCh. 3 - Prob. 27CCh. 3 - Prob. 28CCh. 3 - Prob. 29CCh. 3 - Prob. 30CCh. 3 - Prob. 31CCh. 3 - Prob. 32CCh. 3 - Prob. 33CCh. 3 - Prob. 34CCh. 3 - Prob. 35CCh. 3 - Write a Java program for a matrix class that can...Ch. 3 - Write a class that maintains the top ten scores...Ch. 3 - Prob. 38PCh. 3 - Write a program that can perform the Caesar cipher...Ch. 3 - Prob. 40PCh. 3 - Prob. 41PCh. 3 - Prob. 42PCh. 3 - Prob. 43P
Knowledge Booster
Similar questions
- Use java programming language only.arrow_forwardGiven the linked list data structure, implement a sub-class TSortedList that makes sure that elements are inserted and maintained in an ascending order in the list. So, given the input sequence {1,7,3,11,5}, when printing the list after inserting the last element it should print like 1, 3, 5, 7, 11. Note that with inheritance, you have to only care about the insertion situation as deletion should still be handled by the parent class.arrow_forwardWrite code in java with OOParrow_forward
- Use the API documentation for the AbstractList class to write a concrete class that maintains an unmodifiable list.arrow_forwardDeclare and implement 5 classes: FloatArray, SortedArray, FrontArray, PositiveArray & NegativeArray. 1- The FloatArray class stores a dynamic array of floats and its size. It has:- A parameterized constructor that takes the array size. - An add method that adds a float at the end of the array.- Overloading for the insertion operator << to write the array to afile (ofstream)- Overloading for the extraction operator >> to read the array elements from the file (ifstream) and add them to the array.- A destructor to deallocate the array2- The SortedArray inherits from FloatArray. It has:- A parameterized constructor that takes the array size. - An add method that adds a float at the right place in the arraysuch that the array remains sorted with every add. Don’t add to the array then sort but rather add in the right place.3- The FrontArray inherits from FloatArray. It has:- A parameterized constructor that takes the array size. - An add method that adds a float at the front…arrow_forwardDeclare and implement 5 classes: FloatArray, SortedArray, FrontArray, PositiveArray & NegativeArray 1- The FloatArray class stores a dynamic array of floats and its size. It has:- A parameterized constructor that takes the array size. - An add method that adds a float at the end of the array.- Overloading for the insertion operator << to write the array to afile (ofstream)- Overloading for the extraction operator >> to read the array elements from the file (ifstream) and add them to the array.- A destructor to deallocate the array 2- The SortedArray inherits from FloatArray. It has:- A parameterized constructor that takes the array size. - An add method that adds a float at the right place in the arraysuch that the array remains sorted with every add. Don’t add to the array then sort but rather add in the right place. 3- The FrontArray inherits from FloatArray. It has:- A parameterized constructor that takes the array size. - An add method that adds a float at the front…arrow_forward
- Develop a class ResizingArrayQueueOfStrings that implements the queueabstraction with a fixed-size array, and then extend your implementation to use arrayresizing to remove the size restriction.Develop a class ResizingArrayQueueOfStrings that implements the queueabstraction with a fixed-size array, and then extend your implementation to use arrayresizing to remove the size restriction.arrow_forwardWrite the definitions of the member functions of the classes arrayListType and unorderedArrayListType that are not given in this chapter. The specific methods that need to be implemented are listed below. Implement the following methods in arrayListType.h: isEmpty isFull listSize maxListSize clearList Copy constructor Implement the following method in unorderedArrayListType.h insertAt Also, write a program (in main.cpp) to test your function.arrow_forwardJava Code: Create a Parser class. Much like the Lexer, it has a constructor that accepts a LinkedList of Token and creates a TokenManager that is a private member. The next thing that we will build is a helper method – boolean AcceptSeperators(). One thing that is always tricky in parsing languages is that people can put empty lines anywhere they want in their code. Since the parser expects specific tokens in specific places, it happens frequently that we want to say, “there HAS to be a “;” or a new line, but there can be more than one”. That’s what this function does – it accepts any number of separators (newline or semi-colon) and returns true if it finds at least one. Create a Parse method that returns a ProgramNode. While there are more tokens in the TokenManager, it should loop calling two other methods – ParseFunction() and ParseAction(). If neither one is true, it should throw an exception. bool ParseFunction(ProgramNode) bool ParseAction(ProgramNode) -Creates ProgramNode,…arrow_forward
- This in c++.arrow_forwardThis one in c++.arrow_forwardAdd a new public member function to the LinkedList class named reverse() which reverses the items in the list. You must take advantage of the doubly-linked list structure to do this efficiently as discussed in the videos/pdfs, i.e. swap each node’s prev/next pointers, and finally swap headPtr/tailPtr. Demonstrate your function works by creating a sample list of a few entries in main(), printing out the contents of the list, reversing the list, and then printing out the contents of the list again to show that the list has been reversed. Note: your function must actually reverse the items in the doubly-linked list, not just print them out in reverse order! Note: we won't use the copy constructor in this assignment, and as such you aren't required to update the copy constructor to work with a doubly-linked list. This is what I have so far but its not working! template<class ItemType>void LinkedList<ItemType>::reverse(){ Node<ItemType>*curPtr,*prev,*next;…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning