当我进入'('只有程序说它是balanec !!!! [英] when I entered '(' only the program said it is balanec !!!!

查看:89
本文介绍了当我进入'('只有程序说它是balanec !!!!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经完成了我的工作:


"

在一个程序中使用Stack类,该程序读取一个字符串,一次一个字符,并确定该字符串是否包含平衡括号。也就是说,对于每个左括号(如果有的话),后面的字符串中只有一个匹配的右括号。


"

__________



//Stack.h

展开 | 选择 | Wrap | 行号

解决方案

纠正这个for循环

展开 | 选择 | 换行 | 行号


< blockquote>当我改变循环时,该函数只需要一个字符来测试它,我想要的是填充堆栈并看到''(''和'')''是否平衡...






我不知道如何用这项工作来完成字符串..我认为我不需要它因为我有char而不是它..是我的想法?



当我改变循环时,该函数只需要一个字符来测试它,我是什么想要填充堆栈,看看''(''和'')''是否平衡..



???你是什​​么意思只需要1个字符来测试它?你使用堆栈的方式,当你到达一致(平衡)字符串的末尾时,它保证是空的。它只会包含字符''(''并且只有在没有匹配的'''''时才会出现。


我不知道知道我怎么能用这项工作做字符串..我认为我不需要它因为我有char而不是它..我的想法是对的吗?



只要您只对测试数据感兴趣而不存储它以便以后使用它,那么使用char就可以了。如果您在输入后必须使用该字符串,那么您需要在某处存储字符输入,如字符串。


I have finshed my work on :

"
Use the Stack classes in a program that reads a string, one character at a time, and determines whether the string contains balanced parentheses. That is, for each left parenthesis (if there are any) there is exactly one matching right parenthesis later in the string.

"
__________


//Stack.h

Expand|Select|Wrap|Line Numbers

解决方案

Correct this for loop

Expand|Select|Wrap|Line Numbers


when I changed the loop the function takes only one charcter to test it , what i want is to fill the stack and see is the ''('' and '')'' are balanced or not ..







I do not know how can I do the string with this work .. I think that I do not need it because I have "char" instead of it .. is my think right ?


when I changed the loop the function takes only one charcter to test it , what i want is to fill the stack and see is the ''('' and '')'' are balanced or not ..

??? what do you mean only takes 1 character to test it? The way you are using your stack it is guaranteed to be empty by the time you have go to the end of a conforming(balanced) string. It will only ever contain the character ''('' and only if it does not have a matching '')''.

I do not know how can I do the string with this work .. I think that I do not need it because I have "char" instead of it .. is my think right ?

As long as you are only interested in testing the data and not storing it to use it later then using a char is fine. If you are going to have to use the string once it has been input then you will need somewhere to store the characters input, like a string.


这篇关于当我进入'('只有程序说它是balanec !!!!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆