Concluído

C++ code using data structures

The task is to write a function that checks if strings are balanced. Your code has to have a function named is_balanced which takes one argument: a std::string and returns a boolean. It should return true if the string is balanced, and false otherwise.

The function has to read the string character by character.

The function does not read the string multiple times.

If the function reads a character ', it ignores next characters until it reads the next '.

If the function reads the character ", it ignores next characters until it reads the next " character.

If the function reads the character ( or [, it pushes it on top of a stack.

If the function reads a )it checks the top of the stack and if it is equal to (, it deletes the topmost element of the stack -- otherwise it returns false.

If the function reads a ]it checks the top of the stack and if it is equal to [, it deletes the topmost element of the stack -- otherwise it returns false.

It ignores all other characters.

If after reading the whole string the stack is empty then the function returns true. If it is not empty, the function has to return false.

Examples

std::string s = "asdf";

std::cout << std::boolalpha;

std::cout << s << ": " << is_balanced(s) << std::endl;

s = "()";

std::cout << s << ": " << is_balanced(s) << std::endl;

s = "([])";

std::cout << s << ": " << is_balanced(s) << std::endl;

s = "([)]";

std::cout << s << ": " << is_balanced(s) << std::endl;

s = "[()]";

std::cout << s << ": " << is_balanced(s) << std::endl;

s = "[()";

std::cout << s << ": " << is_balanced(s) << std::endl;

s = "[(";

std::cout << s << ": " << is_balanced(s) << std::endl;

s = "[(([])[()])]";

std::cout << s << ": " << is_balanced(s) << std::endl;

s = "[(' ')]";

std::cout << s << ": " << is_balanced(s) << std::endl;

s = "[('[')]";

std::cout << s << ": " << is_balanced(s) << std::endl;

s = "[('[()')]";

std::cout << s << ": " << is_balanced(s) << std::endl;

s = "[('[()')(\")\")]";

std::cout << s << ": " << is_balanced(s) << std::endl;

s = "\"()[]";

std::cout << s << ": " << is_balanced(s) << std::endl;

s = "\"'''\"";

std::cout << s << ": " << is_balanced(s) << std::endl;

s = "'''";

std::cout << s << ": " << is_balanced(s) << std::endl;

s = "\"\"\"";

std::cout << s << ": " << is_balanced(s) << std::endl;

s = "'\"'\"\"";

std::cout << s << ": " << is_balanced(s) << std::endl;

Should print:

asdf: true

(): true

([]): true

([)]: false

[()]: true

[(): false

[(: false

[(([])[()])]: true

[(' ')]: true

[('[')]: true

[('[()')]: true

[('[()')(")")]: true

"()[]: false

"'''": true

''': false

""": false

'"'"": true

more about project pm

Habilidades: Programação C, Programação C++ , Arquitetura de software

Veja mais: graph data structure c++ source code, data structures programs in java, data structures in c++, data structure program examples, data structures and algorithms in c++, data structure program examples in c, data structure programs in c++ pdf, data structure in c++ by yashwant kanetkar pdf, sorting techniques in data structures using c, introduction to data structures using c, data structures with c using stl, data structures using c tutorial, data structures using c online tutorial, c algorithms and data structures, list project using data structures, project using data structures, project list using data structures, write search query using data structures java, java projects using data structures, reading using data excel

Acerca do Empregador:
( 0 comentários ) Lodz, Poland

ID do Projeto: #17163580

Concedido a:

ansarias21

I have 2 years of working exeperiance in C++.

zł55 PLN em 1 dia
(0 Comentários)
0.0

23 freelancers estão ofertando em média zł78 para esse trabalho

liangjongai

Hi! I'm interesting your project very well. I am a full time devloper. I am mastering c++ and I'm a good Mathematician. And also I have many experience and good skill about data structure algorithm development. L Mais

zł90 PLN em 1 dia
(231 Comentários)
7.1
xzan88

Hi, I have over 10 years of experience in C/C++ programming. I have read the description. I can finish this today. Please message me.

zł90 PLN em 1 dia
(98 Comentários)
6.2
idleswell

Hello, I have 25 years experience programming in C++. I will create a C++ program with an is_balanced function according to the attached specifications. A milestone payment for the full budget for this project mu Mais

zł113 PLN in 3 dias
(184 Comentários)
6.1
vanilladevs

Hello there, lots of experience teaching algorithms and data structures at uni level with C/C++. Let me know the deadline of this balanced string task to see if I can help. Cheers!

zł89 PLN em 1 dia
(45 Comentários)
5.5
zł80 PLN em 1 dia
(35 Comentários)
4.8
BestPartner4You

Hi Sir, I am a super C++ developer and have 7 years of enough experience in this kinds of projects, so I can help you. I checked your all requirements and understood what you want. I will provide you best quality wor Mais

zł115 PLN em 1 dia
(11 Comentários)
4.3
zł105 PLN in 2 dias
(32 Comentários)
4.5
carlosgottberg

Hi, I pretty much have the thing figured out. I've worked with C++ for quite a while and it's not actually that difficult. I'm available for starting asap.

zł75 PLN em 1 dia
(10 Comentários)
4.2
zł85 PLN em 1 dia
(14 Comentários)
3.9
Nerdulent

hi mate....by when do you need the project completed? thanks :)

zł100 PLN em 1 dia
(6 Comentários)
2.6
athulskarun

Hello. I'm a Computer Engineer with 8+ years experience in C++ and C Programming. From our description, I came to know that this is a balanced parenthesis question and I can help you with it. Lets discuss more through Mais

zł75 PLN em 1 dia
(4 Comentários)
2.5
swathi8118

Hi I am a software developer with 6+ years of experience. I mainly work on c++. I would like to discuss more about the project. Looking forward for a positive reply

zł55 PLN em 1 dia
(1 Comentário)
1.0
zł45 PLN in 2 dias
(0 Comentários)
0.0
qiangdaxiang

Hi there. I am very interested in your project. For me it's a piece of cake. I am also available for your further tasks. I will help you instantly. Here's Daxiang for you. Regards.

zł65 PLN em 1 dia
(0 Comentários)
0.0
zł65 PLN em 1 dia
(0 Comentários)
0.0
Hasham241

your work is very for me, i hope i will do this as soon as [login to view URL] more contact me in private chat..........

zł60 PLN em 1 dia
(1 Comentário)
0.0
zł55 PLN em 1 dia
(0 Comentários)
0.0
RisingStar514

Hello How are you I read your job description carefully I have many good experiences in C++ Programming and Algorithm I have take part several in ACM and CodeChef Contest for Algorithm I can quickly your job in s Mais

zł75 PLN em 1 dia
(0 Comentários)
0.0
moussaz

Hi I'm a c++ programmer with more then 2 years of experience Your function is easy to build You can contact me for detail

zł95 PLN em 1 dia
(0 Comentários)
0.0
vasilyalevizos

Hi, I have up to 5 years of experience in c++. Please, don't hesitate to ask me if you are interesting and provide me full details on what you need me to do. Thanks. Have a great day.

zł70 PLN in 5 dias
(0 Comentários)
0.0