Ask C/C++ Expert


Home >> C/C++

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.

C/C++, Programming

  • Category:- C/C++
  • Reference No.:- M93067577

Have any Question?


Related Questions in C/C++

Question 1find the minimum and maximum of a list of numbers

Question: 1. Find the Minimum and Maximum of a List of Numbers: 10 points File: find_min_max.cpp Write a program that reads some number of integers from the user and finds the minimum and maximum numbers in this list. Th ...

Software development fundamentals assignment 1 -details amp

Software Development Fundamentals Assignment 1 - Details & Problems - In this assignment, you are required to answer the short questions, identify error in the code, give output of the code and develop three C# Console P ...

What are the legal requirements with which websites must

What are the legal requirements with which websites must comply in order to meet the needs of persons with disabilities? Why is maximizing accessibility important to everyone?

There are several ways to calculate the pulse width of a

There are several ways to calculate the pulse width of a digital input signal. One method is to directly read the input pin and another method (more efficient) is to use a timer and pin change interrupt. Function startTi ...

Assignment word matchingwhats a six-letter word that has an

Assignment: Word Matching What's a six-letter word that has an e as its first, third, and fifth letter? Can you find an anagram of pine grave. Or how about a word that starts and ends with ant (other than ant itself, of ...

1 implement the binary search tree bst in c using the node

1. Implement the Binary Search Tree (BST) in C++, using the Node class template provided below. Please read the provided helper methods in class BST, especially for deleteValue(), make sure you get a fully understanding ...

Assign ment - genetic algorithmin this assignment you will

ASSIGN MENT - GENETIC ALGORITHM In this assignment, you will use your C programming skills to build a simple Genetic Algorithm. DESCRIPTION OF THE PROGRAM - CORE REQUIREMENTS - REQ1: Command-line arguments The user of yo ...

Project - space race part a console Project - Space Race Part A: Console Implementation

Project - Space Race Part A: Console Implementation INTRODUCTION This assignment aims to give you a real problem-solving experience, similar to what you might encounter in the workplace. You have been hired to complete a ...

Why do researcher drop the ewaste and where does it end

Why do researcher drop the ewaste and where does it end up?

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As