Hello, just started working with queues and need a push in the right direction. We only briefly went over the topic in class and it's an extra credit assignment, so I'd like to complete it and understand what's going on.
Write a program that reads two sentences and reads them into two separate queues. The program should then determine whether the sentences are identical by comparing characters between the two. When two non-identical characters are encountered, the program should display a message indicating that the sentences are not the same. If both queues contain the same set of characters, a message should be stated that they are identical.
make a boolean that defaults to yes
loop through the two containers, checking each value for equality at that index in the respective containers
if that value is not equal, set that boolean to no
end that loop
if the boolean is true, the containers are identical
this would be the simplest way of implementing a comparison function. There are many ways you can optimize it, but worry about that when you've made the initial algorithm.
Be careful about asking school questions, specific questions will garner specific answers, we need to balance giving you a headstart and letting you learn. There are folks on here who will give you the answers to your questions, just remember you're learning to program, not learning to ask programmers questions.
Last point noted. I'm still not getting the desired output though. I've made some progress as seen in the code below but when it gets to the condition, it skips straight to the else even if equal-length / equal-character strings are input. What gives?
#include <iostream>
#include <string>
#include <deque>
using namespace std;
int main()
{
deque<char> str1, str2;
string s;
cout << "Enter string #1: ";
cin >> s;
for (int i = 0; i < s.size(); ++i)
str1.push_back(s[i]);
cout << "Enter string #2: ";
cin >> s;
for (int i = 0; i < s.size(); ++i)
str1.push_back(s[i]);
if (str1.size() == str2.size())
for (int i = 0; i < str1.size(); ++i)
{
if (str1.front() == str2.front())
{
str1.pop_front();
str2.pop_front();
cout << "Character #" << i + 1 << " is identical." << endl;
}
else
cout << "Strings are not identical." << endl;
}
else
cout << "Strings are not identical." << endl;
}