View Single Post
Old 10-12-2005, 03:30 AM   #2 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,726
redhead is on a distinguished road
Wouldn't it be much easier to use std::stack types for the stack, instead of creating your own stack class ?
Then have two stacks, one where the string is stored reversed, and compare the two, if one item in them don't match, then error out.

And for the toupper()/tolower() thingy you might wanna check this thread. As you can see there the shift from lowert to upper is actualy a logic or with 32, aswell as when it's to lowere you're using logic and.
Here is a small program for that
Code:
#include <string>
#include <iostream>
int main()
{
	std::string text("this iS a TEst");
	std::string sResult;
	for(unsigned int i = 0; i < text.size(); ++i)
	  {
	    if(text[i] >= 'A' && text[i] <= 'Z')
	      sResult += (text[i] | 32);
	    else
	      if(text[i] >= 'a' && text[i] <= 'z')
		sResult += (text[i] & (~32));
	      else
		sResult += text[i];
	  }
	std::cout << text << std::endl;
	std::cout << sResult << std::endl;
	return 0;
}
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote