Đã hoàn thành

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

Kĩ năng: Lập trình C, Lập trình C++, Kiến trúc phần mềm

Xem nhiều hơn: 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

Về Bên Thuê:
( 3 nhận xét ) Lodz, Poland

ID dự án: #17163580

Được trao cho:

ansarias21

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

zł55 PLN trong 1 ngày
(6 Đánh Giá)
1.4

20 freelancer đang chào giá trung bình zł77 cho công việc này

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 Thêm

zł90 PLN trong 1 ngày
(257 Nhận xét)
7.6
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 Thêm

zł113 PLN trong 3 ngày
(185 Nhận xét)
6.2
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 trong 1 ngày
(101 Nhận xét)
6.2
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 trong 1 ngày
(46 Nhận xét)
5.6
zł80 PLN trong 1 ngày
(38 Nhận xét)
4.9
zł105 PLN trong 2 ngày
(41 Nhận xét)
4.9
zł85 PLN trong 1 ngày
(20 Nhận xét)
4.1
Nerdulent

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

zł100 PLN trong 1 ngày
(7 Nhận xét)
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 Thêm

zł75 PLN trong 1 ngày
(4 Nhận xét)
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 trong 1 ngày
(4 Nhận xét)
2.6
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 trong 5 ngày
(2 Nhận xét)
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 trong 1 ngày
(1 Nhận xét)
1.0
zł45 PLN trong 2 ngày
(0 Nhận xét)
0.0
zł65 PLN trong 1 ngày
(0 Nhận xét)
0.0
zł55 PLN trong 1 ngày
(0 Nhận xét)
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 trong 1 ngày
(0 Nhận xét)
0.0
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 trong 3 ngày
(0 Nhận xét)
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 Thêm

zł75 PLN trong 1 ngày
(0 Nhận xét)
0.0
arazos

Hello, I can handle it in a few hours. (Why do I need at least 100 characters to describe my proposal?)

zł40 PLN trong 1 ngày
(0 Nhận xét)
0.0