Well, starting from the top:
1. There is an STL container adaptor for stacks.
http://cplusplus.com/reference/stl/stack/
2. Just include <iostream>, without the .h.
3. The #define of N would be better suited as a module-scope constant integer. For example:
1 2 3 4
|
namespace
{
const int N = 10;
}
|
Note, however, that this magic number is still serving as a restriction to the containers size. Consider dynamically allocating the array to get around this.
4. Global variables (i) should be avoided. In this case its only used inside main, anyway.
5. On line 4, typedef could be removed. The name stack may possibly conflict with std::stack if you were to make the std namespace accessible. Consider renaming it or wrapping it in its own namespace. Also, the stack would benefit from being a class with access protection, a constructor, and member functions.
6. The functions need a return value. In this case, void, although optionally pop could return a value.
7. The functions assume that the argument stck is a valid pointer. If it is not, the program will terminate unexpectedly.
8. The stack has no bounds checking. When the stack is emptied, TOP is set to -1. N is then used as an index to the s member. s[-1] would write outside of the allocated memory for s (so would s[10]).
9. As a general rule of thumb, prefer the prefix increment operator over postfix, when the expression does not require the functionality of the postfix operator. Theoretically, the prefix increment is faster but compilers can easily optimise this out.
10. main should return an int, according to the standard.
11. Line 35 contains another magic number, 10, and a std::string would best remove that limitation.
12. cin and cout are in the std namespace. Without explicitly making them available, the compiler will issue unknown identifier errors. One fix would be to prefix them with
std::
.
13. On line 41 (55, too), = is the assignment operator. You want the equality operator ==. Also, the conditional will not work as expected. See:
http://www.cplusplus.com/forum/articles/3483/
14. The switch statement, on line 57, is missing the case for '0'. Also it could be simplified to:
15. Finally, I'm not very confident that once this compiles that the processing of the expression with the pushes and pops will work as expected. It might but I'm not going to sit here and comprehensively think it through.
Sorry about the long list but there's a lot going on here. Hope this helps.