Completed

C++ code using data structures 2

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.

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

Skills: C Programming, C++ Programming, Software Architecture

See more: data structure program examples, c++ stack program example, data structure programs in c++ pdf, stack in data structure, data structures using c++ programs download, data structures programs in c++, data structures and algorithms in c++, c++ data structures book, 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

About the Employer:
( 0 reviews ) Lodz, Poland

Project ID: #17165181

Awarded to:

neos94

Hello, I am very experienced with algorithmic problem solving and can deliver this within minutes :) I have been in competitive programming for 8 years and I took part in International Olympiad in Informatics, which More

zł60 PLN in 1 day
(0 Reviews)
0.0

13 freelancers are bidding on average zł71 for this job

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 algorithm development. Let's go ahead w More

zł90 PLN in 1 day
(231 Reviews)
7.1
bormaa

Dear sir, iam interested in your project i can finish it easily with high quality with least price because iam building my profile. I can provide many design which can satisfy your impression and achieve what you want. More

zł75 PLN in 1 day
(8 Reviews)
4.8
kalyanprakash4

please discuss .........................................................................................................................................................

zł105 PLN in 2 days
(16 Reviews)
4.1
junaidlodhi6

i am an expert in c++... i can give you in 5 hours... looking forward to get some response... thanks!

zł90 PLN in 1 day
(16 Reviews)
3.6
rabnawazjansher8

hi , i can do your C++ assignment .. and i have already done many assignments related to data structure. i have past experience of 3 years. let discuss over chat thanks

zł75 PLN in 1 day
(12 Reviews)
3.4
Davepsingh23

Hello, I have my expertise in C++ and C and I can assure you that I have the right kind of experience and skills for this job. I have 6+ year of experience and these years I have created various projects like Dat More

zł75 PLN in 1 day
(2 Reviews)
2.8
zł40 PLN in 0 days
(1 Review)
1.9
mashreghali

Hi, I have done a similar project before. I have good knowledge of C++ and data structures. I can do your project for you in 1 day.

zł75 PLN in 1 day
(1 Review)
0.8
durgesh8527

Hello Sir/Mam, I have read your post requirement for the " task is to write a function that checks if strings are balanced. ". Now I have some questions to clear the things for this project. I am full time freelancer h More

zł75 PLN in 3 days
(0 Reviews)
0.0
zł30 PLN in 1 day
(0 Reviews)
0.0
arazos

Hello, I wrote the code for the previous one just for fun. The code works completely fine for all inputs.

zł50 PLN in 1 day
(0 Reviews)
0.0
kojecka

Greetings. I have experience teaching data structures and programming classes for a long time (15+ years). So, I have full confidence in delivering your code as required. Looking forward to working with you.

zł85 PLN in 2 days
(0 Reviews)
0.0