473,508 Members | 2,384 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Stack or Queue?

I have a rather pecurliar C++ assignment. I need to create a program (using a stack or queue) to verify if the grouping symbols in an arithmetic expression match. For example:
{25 + (3 - 6) * 8}
In this case they match (one corresponding left and right bracket for both). In this case:
(25 + (3 - 6} * 8)
they don't match (there is a } that should be a )). If anyone can give me an idea or something to get me heading in the correct direction, I'd appreciate it.
Please note: I HAVE to use a stack or queue.
Dec 9 '05 #1
4 2785

deanfamily wrote:
I have a rather pecurliar C++ assignment. I need to create a program (using a stack or queue) to verify if the grouping symbols in an arithmetic expression match. For example:
{25 + (3 - 6) * 8}
In this case they match (one corresponding left and right bracket for both). In this case:
(25 + (3 - 6} * 8)
they don't match (there is a } that should be a )). If anyone can give me an idea or something to get me heading in the correct direction, I'd appreciate it.
Please note: I HAVE to use a stack or queue.


The answer to this is REALLY easy. I am reluctant to even give a hint.

Here is your hint...

What are the main operations of a stack or queue? (in general, not the
std:: versions specifically)

Dec 9 '05 #2
deanfamily wrote:
I have a rather pecurliar C++ assignment. I need to create a program (using a stack or queue) to verify if the grouping symbols in an arithmetic expression match. For example:
{25 + (3 - 6) * 8}
In this case they match (one corresponding left and right bracket for both). In this case:
(25 + (3 - 6} * 8)
they don't match (there is a } that should be a )). If anyone can give me an idea or something to get me heading in the correct direction, I'd appreciate it.
Please note: I HAVE to use a stack or queue.


OK, here's a hint. A stack is LIFO (last in, first out). A queue is
FIFO (first in, first out). When you analyze an arithmetic expression,
and you come across, say, a right parenthesis, do you look at the most
recent symbol you came across (that is, the last thing you added) or
the first symbol you came across (that is, the first thing you added)?

And this isn't a peculiar C++ assignment - sounds like a pretty typical
introductory assignment to me. And a fairly easy one, once you think
it through.

Best regards,

Tom

Dec 9 '05 #3
When is your homework due? Don't you have your textbook with you?
Sashi
roberts.n...@gmail.com wrote:
deanfamily wrote:
I have a rather pecurliar C++ assignment. I need to create a program (using a stack or queue) to verify if the grouping symbols in an arithmetic expression match. For example:
{25 + (3 - 6) * 8}
In this case they match (one corresponding left and right bracket for both). In this case:
(25 + (3 - 6} * 8)
they don't match (there is a } that should be a )). If anyone can give me an idea or something to get me heading in the correct direction, I'd appreciate it.
Please note: I HAVE to use a stack or queue.


The answer to this is REALLY easy. I am reluctant to even give a hint.

Here is your hint...

What are the main operations of a stack or queue? (in general, not the
std:: versions specifically)


Dec 9 '05 #4
deanfamily wrote:
I have a rather pecurliar C++ assignment. I need to create a program
(using a stack or queue) to verify if the grouping symbols in an
arithmetic expression match. For example:
{25 + (3 - 6) * 8}
In this case they match (one corresponding left and right bracket for
both). In this case:
(25 + (3 - 6} * 8)
they don't match (there is a } that should be a )). If anyone can give
me an idea or something to get me heading in the correct direction, I'd
appreciate it.
Please note: I HAVE to use a stack or queue.


Use both. A queue has to begin and end in a parenthesis or a curly brace.
The contents of each queue are the "primary expressions" between the
corresponding symbols. As you encounter an "opening" symbol, start
another queue. As you encounter a "closing" symbol, check the currently
"active" queue and if it's OK, finish it and make a "primary expression"
from it, and add to the previous queue. To maintain active queues, you
will probably need to use a stack.

I don't see any C++ language questions, though.

V
Dec 9 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
12356
by: unified | last post by:
Ok, I'm working on a program that is supposed to compare each letter of a string that is put into a stack and a queue. It is supposed to tell whether or not a word is a palindrome or not. (a...
4
2136
by: alisaee | last post by:
plz check what i have made wrong what is requierd her is to creat class queue and class stack and run the push,pop operation . #include<iostream.h> #include<conio.h> #include<stdio.h> class...
4
6484
by: raghu | last post by:
// Program to implement both stack and queue on an array int main(void) { int a,i; for(i=0;i<5;i++) scanf("%d",&a); // here i'm filling (pushing) the elements for(i=4;i>=0;i--)...
4
1917
by: SP | last post by:
Hi, I've a Stack. Now I would use this to mantain a LIFO objects chain. My problem is that I want to limit the Stack dimension. If the Stack is full and I want to add a object, I eant to remove...
7
7211
by: DevNull | last post by:
Hello everyone, I decided to pick c++ back up after not really having used it much in 10 years. Just as a point of refference, there was no standard C++ last time I used regularly. Anyways...
2
2825
by: waceys | last post by:
hello everybody i need some body help me to make code for a linked list and arrays build stack and queue such that when i push an element in the stack i can dequeue it first from the queue and when...
3
8303
by: mark4asp | last post by:
Stack of limited size containing unique items? Hi guys, How would I implement a stack of limited size containing unique items? For example. Suppose my stack has . I add 2 to it and it is now...
8
3657
by: t | last post by:
The stack container adaptor uses deque as its default underlying sequential container. I don't understand why since we only add elements and remove elements from one side of a stack. Why isn't...
0
2158
by: tabassumpatil | last post by:
Please send the c code for: 1.STACK OPERATIONS : Transfer the names stored in stack s1 to stack s2 and print the contents of stack s2. 2.QUEUE OPERATIONS : Write a program to implement...
0
7115
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7321
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7377
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7036
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7489
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
3179
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1547
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
762
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
414
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.