============================MODULE30======================================= | | | The program examples' source codes have been arranged in the same | | order that appeared in the Tutorial. This is unedited and unverified | | compilation. Published as is basis for educational, reacretional and | | brain teaser purposes. All trademarks, copyrights and IPs, wherever | | exist, are the sole property of their respective owner and/or | | holder. Any damage or loss by using the materials presented in this | | tutorial is USER responsibility. Part or full distribution, | | reproduction and modification is granted to any body. | | Copyright 2003-2005 © Tenouk, Inc. All rights reserved. | | Distributed through http://www.tenouk.com | | | | | =========================================================================== Originally programs compiled using Borland C++. Examples compiled using g++ are given at the end of every Module. For example if you want to compile C++ codes using VC++/VC++ .Net, change the header file accordingly. Just need some modification for the header files...: ------------------------------------------------- #include //for system() #include ... { C++ codes... } ------------------------------------------------- should be changed to: ------------------------------------------------- #include //use C++ wrapper to call C functions from C++ programs... #include using namespace std; ... { C++ codes... } ------------------------------------------------- In VC++/VC++ .Net the iostream.h (header with .h) is not valid anymore. It should be C++ header, so that it comply to the standard. In older Borland C++ compiler this still works, but not proper any more... and for standard C/C++ the portability should be no problem or better you read Module23 at http://www.tenouk.com/Module23.html to get the big picture...For C codes, they still C codes :o) ========================================================================= ============================HERE, ALL C++ codes========================== //stack, pop(), push() //size() and top() #include #include using namespace std; int main() { stack st1, st2; //push data element on the stack st1.push(21); int j=st1.top(); cout<::size_type i; i = st1.size(); cout<<"The stack length is "< #include #include #include using namespace std; int main() { //Declares stack with default deque base container stack deq1; //Explicitly declares a stack with deque base container stack > deq2; //Declares a stack with vector base containers stack > vec; //Declares a stack with list base container stack > lst; cout< #include using namespace std; int main() { queue que1; que1.push(11); que1.push(13); int& x = que1.back(); const int& y = que1.front(); cout<<"The integer at the back of queue que1 is "< #include using namespace std; int main() { queue que; que.push(9); que.push(12); que.push(20); que.push(15); queue ::size_type x; x = que.size(); cout<<"The queue length is "< #include using namespace std; int main() { queue que; que.push(21); que.push(9); que.push(13); queue ::size_type i; i = que.size(); cout<<"The queue length is "< #include using namespace std; int main() { queue que; que.push(23); que.push(15); que.push(32); queue ::size_type i; i = que.size(); cout<<"The queue length is "< #include #include #include using namespace std; int main() { //Declares queue with default deque base container queue que; //Explicitly declares a queue with deque base container queue > que1; //These lines don't cause an error, even though they //declares a queue with a vector base container queue > que2; que2.push(12); //but the following would cause an error because vector has //no pop_front() member function //que2.pop(); //Declares a queue with list base container queue > que3; cout< #include using namespace std; int main() { stack st1, st2; //push data element on the stack st1.push(21); int j=st1.top(); cout<::size_type i; i = st1.size(); cout<<"The stack length is "< #include using namespace std; int main() { queue que; que.push(21); que.push(9); que.push(13); queue ::size_type i; i = que.size(); cout<<"The queue length is "<