Problem Solving with C++ (9th Edition)
9th Edition
ISBN: 9780133591743
Author: Walter Savitch
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
Chapter 18.2, Problem 13STE
Program Plan Intro
Member functions in stack template adapter class:
The member functions in stack templates are given below:
- “s.size()”:
- This function is used to returns the number of elements in the stack.
- “s” is object of stack template adapter class.
- “s.empty()”:
- This function is used to returns “true” if the stack is empty.
- Otherwise, this function returns “false”.
- “s.top()”:
- This function is used to returns top value of the given stack.
- “s.push(Value)”:
- This function is used to insert a “Value” to the top of stack.
- “s.pop()”:
- This function is used to removes the top value of the stack.
- In stack, the “pop” function is a void function.
- So, it does not return the removed value.
- “st1 == st2”:
- This function is used to check whether the
two stacks are equal or not. - If “st1.size == st2.size”, then returns “true”. That is if the number of elements in stack “st1” is equal to corresponding elements in stack “st2”.
- Otherwise, returns “false”.
- This function is used to check whether the
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
In c++
C++ PROGRAMMINGTopic: HashTable - PolyHash Quadratic
Explain the c++ code below.: SEE ATTACHED PHOTO FOR THE PROBLEM INSTRUCTIONS It doesn't have to be long, as long as you explain what the important parts of the code do. (The code is already implemented and correct, only the explanation needed). You can also explain line by line for an upvote, thanks.
EXPLAIN THE CODE BELOW:
#include <cstdlib>
#include <math.h>
#include <cstring>
#include <iostream>
using namespace std;
class HashTable {
string* table;
int N;
int count;
// TODO: Polynomial Hash Code using a=7
int hash_code(string key) {
int code;
int hash = 0;
for (int i = 0; i < key.size(); i++) {
char ch = key[i];
code += ((ch - 96) * pow(7, key.size() - (i + 1)));
}
return code;
}
// TODO: This hash table uses a MAD compression function
// where a = 11, b = 461, p = 919
int compress(int code) {
return (((11*code)+461) % 919) % N;
}…
1- Let A = [2: 0.5: 4],and B=B(2:4).
What are the value of a ,and B?
Chapter 18 Solutions
Problem Solving with C++ (9th Edition)
Ch. 18.1 - If v is a vector, what does v.begin() return? What...Ch. 18.1 - If p is an iterator for a vector object v, what is...Ch. 18.1 - Suppose v is a vector of ints. Write a for loop...Ch. 18.1 - Suppose the vector v contains the letters 'A',...Ch. 18.1 - Suppose the vector v contains the letters 'A',...Ch. 18.1 - Suppose you want to run the following code, where...Ch. 18.2 - Prob. 7STECh. 18.2 - Prob. 8STECh. 18.2 - Prob. 9STECh. 18.2 - Prob. 10STE
Ch. 18.2 - Prob. 11STECh. 18.2 - Prob. 12STECh. 18.2 - Prob. 13STECh. 18.2 - Prob. 14STECh. 18.2 - Prob. 15STECh. 18.2 - Prob. 16STECh. 18.3 - Prob. 17STECh. 18.3 - Prob. 18STECh. 18.3 - Prob. 19STECh. 18.3 - Suppose v is an object of the class vectorint. Use...Ch. 18.3 - Prob. 21STECh. 18.3 - Can you use the copy template function with vector...Ch. 18.3 - Prob. 23STECh. 18 - Prob. 1PCh. 18 - Prob. 2PCh. 18 - Prob. 3PCh. 18 - Prob. 4PCh. 18 - Write a program that allows the user to enter any...Ch. 18 - Prob. 3PPCh. 18 - Prob. 5PPCh. 18 - Solution to Programming Project 18.6 In this...Ch. 18 - Prob. 7PPCh. 18 - You have collected a file of movie ratings where...Ch. 18 - Prob. 9PP
Knowledge Booster
Similar questions
- c++ programming language. Part c I got a respond from you guys and you said it's a writing question but it's not, it a c++ programming question that i need help with please. I need help with part c please.arrow_forwardHow does the --> work in dereferencing a pointer?arrow_forwardFind the error in each of the segments. If the error can be corrected, explain how ? short* numPtr, result;void* genericPtr{numPtr};result = *genericPtr + 7;arrow_forward
- checkBalance Language/Type: Java Stack collections string Related Links: String Write a method named checkBalance that accepts a string of source code and uses a Stack to check whether the braces/parentheses are balanced. Every ( or { must be closed by a } or ) in the opposite order. Return the index at which an imbalance occurs, or -1 if the string is balanced. If any ( or { are never closed, return the string's length. Here are some example calls: // index 0123456789012345678901234567890 checkBalance("if (a(4) > 9) { foo(a(2)); }") returns -1 because balanced checkBalance("for (i=0;i<a(3};i++) { foo{); )") // returns 14 because } out of order checkBalance("while (true) foo(); }{ ()") returns 20 because } doesn't match any { checkBalance("if (x) {") returns 8 because { is never closed // // // Constraints: Use a single stack as auxiliary storage.arrow_forward(Please Help. My professor did not teach us any of this and will not answer my emails) Design a class named Queue for storing integers. Like a stack, a queue holds elements. In a stack, the elements are retreived in a last-in-first-out fashion. In a queue, the elements are retrieved in a first-in-first-out fashion. The class contains: An int[] data field named elements that stores the int values in the queue A data field named size that stores the number of elements in the queue A constructor that creates a Queue object with defult capacity 8 The method enqueue(int v) that adds v into the queue The method empty () that returns true if the queue is empty The method getSize() that returns the size of the queuearrow_forward1. Use a below-given starter code. Use StackInterface.(h), and ArrayStack.(h,cpp). You will write your own StackDriver.cpp application file. IT'S IN C++Also...If the class that you create is Star, remember that you will declare your stack as follows:ArrayStack<Star> myStarStack;and you will push, pop, and peek Star objects.2. Create your own class definition. I should have at least one attribute, a constructor, and set and get methods for each attribute in your class.NOTE: If your class is offensive your lab will be rejected and you will receive a score of zero. I'm sorry I have to say this but there is a history of this happening and it is not appropriate.3. Write a driver program that exercises the Stack class from the downloaded starter code. Create multiple instances of your own class and demonstrate the stack operations: push, pop, and peek. ( you write your own class that you will put on the stack and you will write a driver that pushes, peeks, and pops your class items…arrow_forward
- What is the set builder form for {7,8,9,10...}arrow_forwardIn C++arrow_forwardYou will create two programs. The first one will use the data structure Stack and the other program will use the data structure Queue. Keep in mind that you should already know from your video and free textbook that Java uses a LinkedList integration for Queue. Stack Program Create a deck of cards using an array (Array size 15). Each card is an object. So you will have to create a Card class that has a value (1 - 10, Jack, Queen, King, Ace) and suit (clubs, diamonds, heart, spade). You will create a stack and randomly pick a card from the deck to put be pushed onto the stack. You will repeat this 5 times. Then you will take cards off the top of the stack (pop) and reveal the values of the cards in the output. As a challenge, you may have the user guess the value and suit of the card at the bottom of the stack. Queue Program There is a new concert coming to town. This concert is popular and has a long line. The line uses the data structure Queue. The people in the line are objects…arrow_forward
- Q2 Write the number of point and the letter of the correct answer: 1. The number of fields in the node of double linked list as circular is.............. A. 2 B. 3 C. 4 D. 5 2. Which the following can implement by stack? A. recursive problems B. reveres words C. both a and b D. None of the above 3. The infix expression for the postfix expression: ab+c/ is: A. a+b/c B. (a+b)/c C. a+(b/c) D. None of above 4. With queue data structure, The condition last=first indicates that A. queue is empty B. queue is full C. queue has only one element D. None of the above choose the correct answer (data structure in java) 2 10 (0.5X2 Page 1 of 4arrow_forwardTwo stacks of the same type are the same if they have the same number of elements and their elements at the corresponding positions are the same. Overload the relational operator == for the class stackType that returns true if two stacks of the same type are the same; it returns false otherwise. Also, write the definition of the function template to overload this operator. Write a program to test the various overloaded operators and functions of class stackType.arrow_forwardtypedef struct node_t node_t; struct node_t { }; int32_t value; node_t* next; node_t* insert (node_t* list, int32_t v, int32_t* flag); 3) As you may have noticed from MT1, Howie is lazy. He wants you to write the interface for the following implementation of function copy_to_linked_list. He really appreciates your help! /* copy_to_linked_list int32_t copy_to_linked_list (int32_t a[], int32_t size, node_t** list_p) { int32_t flag, i; for (i = 0; i < size; ++i) { *list_p = insert (*list_p, a[i], &flag); if (-1== flag) return -1; } return 0;arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education