STARTING OUT C++.+MATLAB+MYPROGRAMLABCD
18th Edition
ISBN: 9781323886083
Author: GADDIS/MOORE
Publisher: PEARSON C
expand_more
expand_more
format_list_bulleted
Expert Solution & Answer
Chapter 19, Problem 31RQE
Explanation of Solution
Stack:
A stack is type of container. It performs “Last In First Out”.
- In stack, the item which is inserted at last will be retrieved first.
- A stack can perform two operations. They are:
- Push – Inserting an element inside a stack.
- When the first element is pushed into the stack, the element will be at the “top” the stack. When the second element is added, the first element is pushed down and the second element will be at the top position, like this it goes on until the element which pushed at last will be at the top of the stack...
- Push – Inserting an element inside a stack.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Computer Science
In a stack with 15 elements assume that the data elements are integer values. Write afunction that pops the elements one by one, add 5 to each integer and push the elementback to the stack.
C#
Reverse the stack - This procedure will reverse the order of items in the stack. This one may NOT break the rules of the stack. HINTS: Make use of more stacks. Arrays passed as parameters are NOT copies. Remember, this is a procedure, not a function.
private int [] stack; private int size;
public void ReverseStack(){
}
C++
Please help me modify this coding which need to apply a linked list to store the node. Also use a stack concept.
The code:
#include<iostream>#include<stdlib.h>#include<string.h>
using namespace std; struct node{ char data[100]; struct node* next; };
int words = 0;
// function for add values to stackstruct node* add(struct node* stack, char *str){ struct node* tp = (struct node*)malloc(sizeof(struct node)); strcpy(tp->data,str); tp->next = stack; words++; return tp; }
//redo functionvoid redo(struct node* stack){ if(stack == NULL) return; words++;
}
//undo functionvoid undo(struct node* stack){ if(stack == NULL) return; words--;
}
//print functionint print(struct node* stack,int idx){ if(stack == NULL) return 0; idx = print(stack->next,idx); if(idx<words) cout<<"\n"<<stack->data; return idx+1;
}
//function for save in fileint save_words(FILE* filePointer, struct node*…
Chapter 19 Solutions
STARTING OUT C++.+MATLAB+MYPROGRAMLABCD
Ch. 19.1 - Describe what LIFO means.Ch. 19.1 - What is the difference between static and dynamic...Ch. 19.1 - What are the two primary stack operations?...Ch. 19.1 - What STL types does the STL stack container adapt?Ch. 19 - Prob. 1RQECh. 19 - Prob. 2RQECh. 19 - What is the difference between a static stack and...Ch. 19 - Prob. 4RQECh. 19 - Prob. 5RQECh. 19 - The STL stack is considered a container adapter....
Ch. 19 - What types may the STL stack be based on? By...Ch. 19 - Prob. 8RQECh. 19 - Prob. 9RQECh. 19 - Prob. 10RQECh. 19 - Prob. 11RQECh. 19 - Prob. 12RQECh. 19 - Prob. 13RQECh. 19 - Prob. 14RQECh. 19 - Prob. 15RQECh. 19 - Prob. 16RQECh. 19 - The STL stack container is an adapter for the...Ch. 19 - Prob. 18RQECh. 19 - Prob. 19RQECh. 19 - Prob. 20RQECh. 19 - Prob. 21RQECh. 19 - Prob. 22RQECh. 19 - Prob. 23RQECh. 19 - Prob. 24RQECh. 19 - Prob. 25RQECh. 19 - Prob. 26RQECh. 19 - Write two different code segments that may be used...Ch. 19 - Prob. 28RQECh. 19 - Prob. 29RQECh. 19 - Prob. 30RQECh. 19 - Prob. 31RQECh. 19 - Prob. 32RQECh. 19 - Prob. 1PCCh. 19 - Prob. 2PCCh. 19 - Prob. 3PCCh. 19 - Prob. 4PCCh. 19 - Prob. 5PCCh. 19 - Dynamic String Stack Design a class that stores...Ch. 19 - Prob. 7PCCh. 19 - Prob. 8PCCh. 19 - Prob. 9PCCh. 19 - Prob. 10PCCh. 19 - Prob. 11PCCh. 19 - Inventory Bin Stack Design an inventory class that...Ch. 19 - Prob. 13PCCh. 19 - Prob. 14PCCh. 19 - Prob. 15PC
Knowledge Booster
Similar questions
- T/F An error is thrown if the character '\n' is pushed in to the character stack.arrow_forwardOCaml Code: I need help with writing the push and pop statements in order to create an interpreter for OCaml. I need help with writing the print statement as well. The println command pops a string off the top of the stack and writes it, followed by a newline, to the output file that is specified as the second argument to the interpreter function. In the case that the top element on the stack is not a string, it should be returned to the stack and an :error: pushed. If the stack is empty, an :error: shall be pushed. Below is the unfinished code. Make sure to use the test cases as well and show the screenshots of the code passing the test cases. Attached is info. for push and pop. interpreter.ml type stackValue = BOOL of bool | INT of int | ERROR | STRING of string | NAME of string | UNIT type command = ADD | SUB | MUL | DIV | PUSH of stackValue | POP of stackValue | REM | NEG | TOSTRING | SWAP | PRINTLN | QUIT let interpreter (input, output) = let ic = open_in input in…arrow_forwardstruct Faculty { int id; char name[30]; char status[10]; //status permanent or visiting Faculty next; }; Assume we have three stacks S, V and P. S is a stack having mix data of visiting and permanent faculty members, V is empty and for visiting faculty memebrs and P is also empty for permanent faculty members. Using primitive functions of stack write a C++ code which reads entire data from S and write on respective stack V or P.arrow_forward
- (Postfix Evaluation) Write a program that evaluates a valid postfix expression such as 6 2 + 5 * 8 4 / -The program should read a postfix expression consisting of digits and operators into a string. Using modified versions of the stack functions implemented earlier in this chapter, the program should scan the expression and evaluate it. The algorithm is as follows: While you have not reached the end of the string, read the expression from left to right. If the current character is a digit, Push its integer value onto the stack (the integer value of a digit character is its value in the computer’s character set minus the value of '0' in the computer’s character set). Otherwise, if the current character is an operator, Pop the two top elements of the stack into variables x and y. Calculate y operator x. Push the result of the calculation onto the stack. When you reach the end of the string, pop the top value of the stack. This is the result of the postfix expression. [Note: In Step 2…arrow_forwardHi please help me thankyou so much FILE: Stack.hGiven the Stack.h above and the following data is to be entered by a user:{ 83, 84, 65, 82, 71, 78, 79, 67 }Write a main program that uses Stack.h library to perform the following pseudo-code:1. create stack S1 and stack S2 as character2. start loop 8 times3.accept data from user4.if the data entered is odd number5.push into S16.else if the data entered is even number7.8. end loop9. display top S1push into S210. pop S111. start loop S2 is not empty12.display top S113.pop S114.display top S215.pop S216. end loop17. display top S118. роp S1arrow_forwardWhat will be the stack content after following operations: Push 5 Push 8 Pop Push 1 Push 12 Poparrow_forward
- Q3: Write the C++ code of Stack which is performed multiple task which are given below and performed all task by using Arrays. Push values 10, 20, 5 , 50, 40, 60, 45 Pop values 45, 60, and 40 Sort all values in Stack Please create is empty and stack function for telling them stack is empty or full.NOTE: PLEASE SOLVE THE QUESTION PROPERLY AND ACCORDING TO THE REUIRED THINGS.arrow_forwardQ1- Write a program to insert five elements in the stack and print the top element using top() and print the size of the stack and check if the stack is empty or not.arrow_forwardQ3: Write the C++ code of Stack which is performed multiple task which are given below and performed all task by using Arrays. Push values 10, 20, 5 , 50, 40, 60, 45 Pop values 45, 60, and 40 Sort all values in Stack Please create is empty and stack function for telling them stack is empty or full.arrow_forward
- Points to be noted: **Please use Python 3 and do not use any built-in function **Do not just copy paste from any other sources, come up with an unique solution. **Solve the above problem using a linked list based stack.arrow_forwardData Structures , Code C++ Suppose that p, q, and r are all pointers to nodes in a linked list with 15 nodes. The pointer p points to the first node, q points to the 8th node, and r points to the last node. Write a few lines of code that will make a new copy of the list. You code should set THREE new pointers called x, y, and z so that: x points to the first node of the copy, y points to the 8th node of the copy, and z points to the last node of the copy.arrow_forwardThis code will be in C++ and will have 3 files. This lab will test your ability to use a custom stack class and a custom queue class. It will also test your ability to use a standard algorithm from STL. ReOrder ReOrder() takes three arguments as shown in Reorder.cpp. Complete this function using stack and queue. The number 0 is used as a delimiter between sets of numbers. The new array should have all negative numbers on one side and all positive numbers on the other side. The zero should be pushed to the end of the array. See the sample run below. Custom Compare Function The custom compare function is used in conjunction with the standard sort function. The numbers to be sorted are of a standard data type but create this custom compare function anyway. The function should result in a sorted array from the greatest number to the least number. Sample Run A sample run is as follows: array: -3 2 -1 5 1 -4 0 11 12 13 -11 -12 0 -1 -2 6 8 7newArray: -3 -1 -4 1 5 2 -11 -12 13 12 11 -1 -2 7 8…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Systems ArchitectureComputer ScienceISBN:9781305080195Author:Stephen D. BurdPublisher:Cengage LearningC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
Systems Architecture
Computer Science
ISBN:9781305080195
Author:Stephen D. Burd
Publisher:Cengage Learning
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning