(This project requires that you know what a stack is and how to use dynamic arrays. Stacks are covered in Chapter 14; dynamic arrays are covered in Chapter 9. This is an appropriate project only if you have covered Chapters 9 and 14.) Write a template version of a stack class. Use a type parameter for the type of data that is stored in the stack. Use dynamic arrays to allow the stack to grow to hold any number of items.
Want to see the full answer?
Check out a sample textbook solutionChapter 17 Solutions
Problem Solving with C++ - MyProgrammingLab
Additional Engineering Textbook Solutions
Database Concepts (7th Edition)
Computer Science: An Overview (13th Edition) (What's New in Computer Science)
Java: An Introduction to Problem Solving and Programming (8th Edition)
Starting Out with Python (3rd Edition)
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
Starting Out with Programming Logic and Design (4th Edition)
- IN JAVA Suppose that in the array-based stack, the array doubles in size after multiple push operations. But later on, fewer than half of the array’s locations might actually be used by the stack due to pop operations. Revise the implementation so that its array also can shrink in size as objects are removed from the stack. Accomplishing this task will require two new private methods, as follows: The first new method checks whether we should reduce the size of the array: private boolean isTooBig() This method returns true if the number of entries in the stack is less than half the size of the array and the size of the array is greater than 20. The second new method creates a new array that is three quarters the size of the current array and then copies the objects in the bag to the new array: private void reduceArray() Implement each of these two methods, and then use them in the definition of pop()arrow_forwardI am writing a stack code, where there are two stacks that reads an array of 40 numbers and puts them in ascending and descending order. I put my code on the bottom. The requirements of the code was to write the stack functions using arrays, but whenever i run the code it does not work. However, if use stack in built function the code works. Help me please. PS: I Attached the code requirements. struct Stack1 { int *arr; int NextIndex; int capacity; Stack1() { capacity = 20; arr = new int[capacity]; NextIndex = 0; } int size () { return NextIndex; } bool isEmpty() { if (NextIndex == 0) { return true; } else return false; } void push(int ele) { if (NextIndex == capacity) { int *newArr = new int[2*capacity]; for(int i = 0; i < capacity; i++) {…arrow_forwardMy attempts at this kept giving me exception errors, I would like to compare and see what it should actually look like. I really need help with is, please Create a Java program that uses a stack to return a list containing all permutations of a given string, and then checks to see which ones are English words. It should read words from the input and create and check the permutations for each word. For example, there are six permutations of the letters in the string "tra": tra, rta, rat, tar, atr, art implementation should include a GetPermutations class (this is the client class, driver class, demo class or console class) and a PermutationsCalculator. the program should determine which of the permutations is an English word by looking them up in a dictionary text file (just a fe words). PermutationsCalculator class Fields: a stack for calculating the permutations; an ArrayList to hold all permutations an ArrayList to hold unique permutations. an ArrayList to hold the unique English…arrow_forward
- For the code shown in the screenshot below, draw a picture of the program stack when the function findSlope() is called the first time. You only have to draw the part of the stack for findZero() and findSlope().arrow_forwardin java language Write a program in which you create an object of type ArrayList named BZ and then add 3 elements in this object and then copy the elements of the object in another object QZ and then cancel the elements of the object BZ and then write the necessary print statements to show it?arrow_forwardI'm trying to understand LargeIntList classes for lists, I was wondering these statements or True or False? either or, can you please explain your answers? Thank you. Uses the “by copy” approach with its elements. Implements the ListInterface interface. Keeps its data elements sorted. Allows duplicate elements. Uses the LLNode class of the support package. Throws an exception if an iteration “walks off ” the end of the list. Throws an exception if an element is added when it is "full". Supports addition of elements at the front of the list, the end of the list, and anywhere in between. Can hold objects of any Java class. Has only O(1) operations, including its constructor. Provides more than one Iterator.arrow_forward
- Write a java program that uses an ArrayList object to store the following set of names in memory: [Steve, Tim, Lucy, Pat, Angela, Tom] Now write some more code so that the same ArrayList object is augmented with the name 'Steve' after the name 'Lucy' After the ArrayList object has been augmented with the new name, display the original and new lists on the console (as shown below), to verify that the new name is positioned correctly in the list.arrow_forwardI ASK THIS QUESTION HERE AND YOUR EXPERT SOLVE IT THIS WAY BUT CAN YOU WRITE THE main ( ) FOR THIS CODE Consider the following implementation of the node and doubly linked-list: template <class type>class node{public:type info;node<type> * next;// nextnode<type> * prev;//back }; template <class type>class doubly_linked_list{//data membersprivate:node<type> *head, *tail;int length;public:doubly_linked_list(){head = tail = NULL;length = 0;}bool isEmpty(){ // return (head==NULL);if (head == NULL)return true;elsereturn false;} void Append(type e){node<type> *newnode = new node<type>;newnode->info = e;if (isEmpty()){newnode->next = NULL;newnode->prev = NULL;head = newnode;tail = newnode;}else{tail->next = newnode;newnode->prev = tail;newnode->next = NULL;tail = newnode;}++length; } void Display(){if (isEmpty()) { cout << "The linked list is empty !!!!"; return; }cout << "list elements: ";node<type> *…arrow_forward1- Start by writing your choice from the list given above. Part a. Explain the important technical details about your choice. 2-(continued) Start by again writing your choice from the list given above. Part b. Most of the ADTs in this class were implemented using arrays and linked lists. If appropriate for the ADT you chose in part a., explain which one (an array or a linked list) you would choose to implement it and why. If it doesn’t make sense to implement your ADT using an array or a linked list, explain which other data structure you would use to implement your ADT.arrow_forward
- Answer the given question with a proper explanation and step-by-step solution. Hello team, Need some help with problems below using the langauge JAVA. I need to modify the CalcParser class provided below. I need this to produce a string containing commands to evaluate the expression on a stack machine. For example, if you give the command java CalcParser 1+2*3, the output should be a sequence of stack commands such as this: push 1.0 push 2.0 push 3.0 multiply add 7.0 For the command java CalcParser (1+2)*3, on the other hand, it should print a sequence like this: push 1.0 push 2.0 add push 3.0 multiply 9.0 CODE:public class CalcParser { private CalcLexer lexer; private String errorMessage = null; private double value; public CalcParser(String s) { lexer = new CalcLexer(s);errorMessage = lexer.getErrorMessage();if (errorMessage != null) return; value = parseExpression();if (errorMessage != null) return; match(CalcLexer.EOLN_TOKEN);if (errorMessage != null) return; } public String…arrow_forwardYou are given an array-like data structure Listy which lacks a size method. It does, however, have an elementAt ( i) method that returns the element at index i in 0( 1) time. If i is beyond the bounds of the data structure, it returns -1. (For this reason, the data structure only supports positive integers.) Given a Listy which contains sorted, positive integers, find the index at which an element x occurs. If x occurs multiple times, you may return any index. Write code with explanationarrow_forwardUsing java, write an easier version of a linked list with only a couple of the normal linked list functions and the ability to generate and utilize a list of ints. The data type of the connection to the following node can be just Node, and the data element can be just an int. You will need a reference like (Java) or either a reference to the first node, as well as one to the last node. (Answer the following questions) 1) Create a method or function that accepts an integer, constructs a node with that integer as its data value, and then includes the node to the end of the list. If the new node is the first one, this function will also need to update the reference to the first node. This function will need to update the reference to the final node. Consider how to insert the new node following the previous last node, and keep in mind that the next reference for the list's last node should be null. 2) Create a different method or function that iteratively explores the list, printing…arrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning