Write a code to reverse the order of the items in q

Assignment Help C/C++ Programming
Reference no: EM132080103

You need some help with some stack/queue questions!

1. A programmer wishes to do parenthesis matching, but does not want to use a stack. The programmer thus decides to simply keep three variables, ParenCount, BracketCount, and BraceCount to keep track of the number of '(', '[', and '{' characters, respectively.

The idea is that when a leftparen is seen, the corresponding variable is incremented and when a rightparen is seen, the corresponding variable is decremented. The expression is said to have balanced parentheses if the three variables are all zero after the expression has been entirely read. Will this algorithm work for checking parenthesis-matching? If so, why? If not, say why not and give a counterexample.

2. Let Q be a non-empty queue and let S be an empty stack. Write C++ code to reverse the order of the items in Q.

3. Write a C++ function queue copy_queue(queue &Q) that returns a new queue containing all of the items in Q in the same order that they were found in Q. The original queue Q must end up unchanged.

4. Write a C++ function void SelectItem(stack &S, ItemType n); that finds the first occurrence of item n on stack S and moves it to the top of the stack, leaving the other stack items in their original order. You may assume that the operator == is valid for ItemType. Note that the stack may be empty or that n may not be on the stack.

5. Let S be a stack of positive integers and let x be an integer variable. Write C++ code fragments to perform each of the following operations:

1. Set x to the top element of S and leave the top element of S unchanged. If S is empty, set x to -1.

2. Set x to the third element from the top in S, provided that S contains at least three integers. If not, set x to -1. Leave S unchanged.

3. Set x to the bottom element of S (or to -1 if S is empty) and leave S unchanged.

4. Delete all occurrences of x from S, leaving the other elements of S in the same order.

Reference no: EM132080103

Questions Cloud

Draw a truth table to represent the problem : Draw a truth table to represent the problem and use it to construct a Karnaugh map. Construct a circuit to implement the function using NAND gates only.
Test for balanced parenthesis and balanced brackets : Write a program to read in a text file (of your own making) and test for balanced parenthesis and balanced brackets. Call the file: "assn3data.txt".
What will the final temperature be in kelvin : The pressure doesn't change and the amount of gas in the balloon doesn't change.
Whams of a sample of umbo : The ponderosity in whams of a sample of umbo is directly proportional to the number of frenks in the sample and to its muckle, measured in flugges.
Write a code to reverse the order of the items in q : Write a C++ function void SelectItem(stack &S, ItemType n); that finds the first occurrence of item n on stack S and moves it.
What is the ph of a buffer solution : What is the pH of a buffer solution comprised of 3.95 M HCOOH and 0.35 M HCOO- in a 1 L solution after 0.30 mol NaOH (where Ka = 1.77 x 10-4) is added?
Complete product design specification : Teesside University - Derive at least four concept designs to satisfy the given specification. Use short written descriptions and simple sketches to illustrate
Chemiluminescent chemical reaction : In a university laboratory experiment the rate of disappearance of ozone (O3) was measured to be 9 x 10-3 M/s. Simultaneously, the concentration of ozone
Write a java method to take a positive integer value : Write a java method to take a positive integer value as its parameter and returns a string of 1s and 0s that represents its binary value.

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Create program that uses functions and reference parameters

Create program that uses functions and reference parameters, and asks user for the outside temperature.

  Write a program using vectors and iterators

Write a program using vectors and iterators that allows a user to maintain a personal list of DVD titles

  Write the code required to analyse and display the data

Calculate and store the average for each row and column. Determine and store the values for the Average Map.

  Write a webservices application

Write a webservices application that does a simple four function calculator

  Iimplement a client-server of the game

Iimplement a client-server version of the rock-paper-scissors-lizard-Spock game.

  Model-view-controller

Explain Model-View-Controller paradigm

  Design a nested program

How many levels of nesting are there in this design?

  Convert celsius temperatures to fahrenheit temperatures

Write a C++ program that converts Celsius Temperatures to Fahrenheit Temperatures.

  Evaluate and output the value in the given base

Write C program that will input two values from the user that are a Value and a Base with which you will evaluate and output the Value in the given Base.

  Design a base class shape with virtual functions

Design a base class shape with virtual functions

  Implementation of classes

Implementation of classes Chart and BarChart. Class barChart chould display a simple textual representation of the data

  Technical paper: memory management

Technical Paper: Memory Management, The intent of this paper is to provide you with an in depth knowledge of how memory is used in executing, your programs and its critical support for applications.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd