Suoritettu

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

Taidot: C-ohjelmointi, C++ -ohjelmointi, tietojärjestelmäarkkitehtuuri

Näytä lisää: 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

Tietoa työnantajasta:
( 2 arvostelua ) Lodz, Poland

Projektin tunnus: #17163580

Myönnetty käyttäjälle:

ansarias21

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

zł55 PLN 1 päivässä
(5 Arvostelua)
1.2

22 freelanceria on tarjonnut keskimäärin %project_bid_stats_avg_sub_26% %project_currencyDetails_sign_sub_27% tähän työhön

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 Lisää

zł90 PLN 1 päivässä
(248 arvostelua)
7.5
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 1 päivässä
(98 arvostelua)
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 Lisää

zł113 PLN 3 päivässä
(184 arvostelua)
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 1 päivässä
(46 arvostelua)
5.6
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 Lisää

zł115 PLN 1 päivässä
(15 arvostelua)
4.9
zł80 PLN 1 päivässä
(38 arvostelua)
4.9
zł105 PLN 2 päivässä
(37 arvostelua)
4.8
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 1 päivässä
(10 arvostelua)
4.2
zł85 PLN 1 päivässä
(20 arvostelua)
4.1
Nerdulent

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

zł100 PLN 1 päivässä
(7 arvostelua)
2.8
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 Lisää

zł75 PLN 1 päivässä
(4 arvostelua)
2.4
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 1 päivässä
(3 arvostelua)
1.7
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 1 päivässä
(1 arvostelu)
1.0
zł45 PLN 2 päivässä
(0 arvostelua)
0.0
zł65 PLN 1 päivässä
(0 arvostelua)
0.0
zł55 PLN 1 päivässä
(0 arvostelua)
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 Lisää

zł75 PLN 1 päivässä
(0 arvostelua)
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 1 päivässä
(0 arvostelua)
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 5 päivässä
(0 arvostelua)
2.5
gurmeet1986

Hi, I have already worked on similar assignments although it is first job on this site but I was involved in this type work with local client. I am free in these days and can pick this task up. Thanks

zł90 PLN 3 päivässä
(0 arvostelua)
0.0