Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
11th Edition
ISBN: 9780134670942
Author: Y. Daniel Liang
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
Chapter 10, Problem 10.10PE
Program Plan Intro
Creates a class Queue and performs enqueue and dequeue operations
Program Plan:
- Define the required public class definition.
- Define the main function in the class using public static void main(String[] args).
- Create the objects and pass the required arguments.
- Declare for loop.
- Declare the required queue.
- Declare while loop.
- Print the data field using System.out.println().
- Close the main function.
- Define the main function in the class using public static void main(String[] args).
- Close the public class definition.
- Define the required class definition.
- Declare the required private data fields.
- Construct the required queue.
- Add the new integer to the queue using enqueue().
- Declare if statement.
- Remove the element from the queue using dequeue().
- Declare for loop.
- Check whether the queue is empty.
- Return the required value.
- Get the size of the queue.
- Return the required value.
- Close the public class definition.
Expert Solution & Answer
Trending nowThis is a popular solution!
Students have asked these similar questions
Course: Data Structure and Algorithims
Language: Java
Kindly make the program in 2 hours.
Task is well explained.
You have to make the proogram properly in Java:
Restriction: Prototype cannot be change you have to make program by using given prototype.
TAsk:
Create a class Node having two data members
int data;
Node next;
Write the parametrized constructor of the class Node which contain one parameter int value assign this value to data and assign next to null
Create class LinkList having one data members of type Node.
Node head
Write the following function in the LinkList class
publicvoidinsertAtLast(int data);//this function add node at the end of the list
publicvoid insertAthead(int data);//this function add node at the head of the list
publicvoid deleteNode(int key);//this function find a node containing "key" and delete it
publicvoid printLinkList();//this function print all the values in the Linklist
public LinkListmergeList(LinkList l1,LinkList l2);// this function…
In C++ Please
1. Stack Implementation
Write a method called insert for the class Stack. The method shall be
implemented using an array-based structure. You can assume that String[]
stack is defined in the class, which is responsible to store the elements and
responsible to enforce the order of first-in last-out, a.k.a., FIFO. Additionally, you
can assume there is a pointer called top, that indicates the position of the top of
the stack, pointing to the next available position to insert.
The method shall:
• take a String s as a parameter, and shall add it at the top of the stack.
shall return true if the element s was added successfully at the top of the
stack, false otherwise.
.
. The method must check boundaries of capacity and limitation of the Stack. In
case the method is invoked to insert an element of the top of the stack that
exceeds its current capacity, the method shall handle the situation properly.
Do not provide the entire Stack implementation, only the code solution of the
method.
Chapter 10 Solutions
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
Ch. 10.2 - Prob. 10.2.1CPCh. 10.3 - Is the BMI class defined in Listing 10.4...Ch. 10.4 - Prob. 10.4.1CPCh. 10.4 - Prob. 10.4.2CPCh. 10.4 - Prob. 10.4.3CPCh. 10.4 - Prob. 10.4.4CPCh. 10.7 - Prob. 10.7.1CPCh. 10.7 - Prob. 10.7.2CPCh. 10.7 - How do you convert an integer into a string? How...Ch. 10.7 - Show the output of the following code: public...
Ch. 10.7 - Prob. 10.7.5CPCh. 10.8 - What are autoboxing and autounboxing? Are the...Ch. 10.8 - Show the output of the following code. public...Ch. 10.9 - What is the output of the following code? public...Ch. 10.10 - Suppose s1, s2, s3, and s4 are four strings, given...Ch. 10.10 - To create the string Welcome to Java, you may use...Ch. 10.10 - What is the output of the following code? String...Ch. 10.10 - Let s1 be Welcome and s2 be welcome Write the...Ch. 10.10 - Prob. 10.10.5CPCh. 10.10 - Prob. 10.10.6CPCh. 10.10 - Prob. 10.10.7CPCh. 10.10 - Prob. 10.10.8CPCh. 10.10 - What is wrong in the following program? 1public...Ch. 10.10 - Show the output of the following code: public...Ch. 10.10 - Show the output of the following code: public...Ch. 10.11 - Prob. 10.11.1CPCh. 10.11 - Prob. 10.11.2CPCh. 10.11 - Prob. 10.11.3CPCh. 10.11 - Prob. 10.11.4CPCh. 10.11 - Prob. 10.11.5CPCh. 10.11 - Suppose s1 and s2 are given as fot tows:...Ch. 10.11 - Show the output of the following program: public...Ch. 10 - (The Time class) Design a class named Time. The...Ch. 10 - (The BMI class) Add the following new constructor...Ch. 10 - (The MyInteger class) Design a class named...Ch. 10 - Prob. 10.4PECh. 10 - (Display the prime factors) Write a program that...Ch. 10 - (Display the prime numbers) Write a program that...Ch. 10 - Prob. 10.7PECh. 10 - Prob. 10.8PECh. 10 - (The Course class) Revise the Course class as...Ch. 10 - Prob. 10.10PECh. 10 - Prob. 10.11PECh. 10 - (Geometry: the Triangle2D class) Define the...Ch. 10 - (Geometry: the MyRectangle 2D class) Define the...Ch. 10 - (The MyDate class) Design a class named MyDate....Ch. 10 - (Geometry: the bounding rectangle) A bounding...Ch. 10 - (Divisible by 2 or 3) Find the first 10 numbers...Ch. 10 - (Square numbers) Find the first 10 square numbers...Ch. 10 - (Mersenne prime)A prime number is called a...Ch. 10 - (Approximate e) Programming Exercise 5.26...Ch. 10 - (Divisible by 5 or 6) Find the first 10 numbers...Ch. 10 - (Implement the String class) The String class is...Ch. 10 - (Implement the String class) The String class is...Ch. 10 - (Implement the Character class) The Character...Ch. 10 - (New string split method) The split method in the...Ch. 10 - (Implement the StringBuilder class) The...Ch. 10 - (Implement the StringBuilder class) The...
Knowledge Booster
Similar questions
- head = (node *)malloc(sizeof(node)); which returns a pointer to a structure of type node that has been type defined earlier. The linked list is then created by the function create. The function requests for the number to be placed in the current node that has been created. If the value assigned to the current node is -999, then null is assigned to the pointer variable next and the list ends. Otherwise, memory space is allocated to the next node using again the malloc function and the next value is placed into it. Not that the function create calls itself recursively and the process will continue until we enter the number -999. The items stored in the linked list are printed using the function print which accept a pointer to the current node as an argument. It is a recursive function and stops when it receives a NULL pointer. Printing algorithm is as follows; 1. Start with the first node. 2. While there are valid nodes left to print a) print the current item and b) advance to next node…arrow_forwardSolve in C Program Implement a program using stack and queue operationsarrow_forwardA "generic" data structure cannot use a primitive type as its generic type. O True Falsearrow_forward
- Data Structure & Algorithum java program Do the following: 1) Add a constructor to the class "LList" that creates a list from a given array of objects.2) Add a method "addAll" to the "LList" class that adds an array of items to the end of the list. The header of the method is as follows, where "T" is the generic type of the objects in the list. 3) Write a Test/Driver program that thoroughly tests all the methods in the class "LList".arrow_forwardWhen a stack is created, what are the initial values in the elements array?arrow_forwardLanguage: JAVA Script write a function 'keyValueDuplicates (obj) that takes an object as an argument and returns an array containing all keys that are also values in that object. Examples: obj1 = { orange: "juice", apple: "sauce", sauce: "pan" }; console.log(keyValueDuplicates (obj1)); // ["sauce"] obj2 = { big: "foot", foot: "ball", ball: "boy", boy: "scout"};console.log(keyValueDuplicates(obj2)); // ["foot", "ball", "boy"] obj3 = { pizza: "pie", apple: "pie" pumpkin: "pie"); console.log(keyValueDuplicates (obj3)); // [] *******************************************************************/function keyValueDuplicates (obj) { | // Your code here } /*****DO NOT MODIFY ANYTHING UNDER THIS LINE*********/ try { | module.exports = keyValueDuplicates; } catch (e) { | module.exports = null;}arrow_forward
- Double pointers: Describe how this operation can be done in O(1) time if there are pointers in each node to both the previous and the next node.arrow_forward1- 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 of the array.4- The PositiveArray that inherits from SortedArray. It has:- A parameterized constructor…arrow_forwarddef get_task(task_collection, ...): """ param: task_collection (list) - holds all tasks; maps an integer ID/index to each task object (a dictionary) param: ... (str) - a string that is supposed to represent an integer ID that corresponds to a valid index in the collection returns: 0 - if the collection is empty. -1 - if the provided parameter is not a string or if it is not a valid integer Otherwise, convert the provided string to an integer; returns None if the ID is not a valid index in the list or returns the existing item (dict) that was requested. """arrow_forward
- A dequeue is a list from which elements can be inserted or deleted at either end a. Develop an array based implementation for dequeue. b. Develop a pointer based implementation dequeue.arrow_forwardIn c++ Also add comments explaining each linearrow_forwardDo in C Program Implement using stack and queue operationsarrow_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