November 01, 2014

String Reverse Program in C++

write a c++ program to reverse a string, reverse string c++ example, c++ reverse string function, c++ programs using strings, working with strings in c++, c++ function returning a string

write a c++ program to reverse a string

#include <iostream>
#include <string>


using namespace std;
template <class T>
class stack {
public:
stack(int size = 100) : max_len(size), top(EMPTY), s(new T[size]) { }
~stack() { delete []s;}
void reset() { top = EMPTY;}
void push(T c) { s[++top] = c;}
T pop() { return s[top--];}
bool empty() const { return top ==EMPTY; }
bool full() const { return top == max_len -1;}
private:
enum {EMPTY = -1};
T* s;
int max_len;
int top;
};

int main()
{
    stack<char> s;
    string c = "My name is Nilkanth";


cout<<"\n The original string is: \n";
for( int i=0;i<=c.length();i++)
{
    s.push(c[i]);

    cout<<c[i];
}

cout<<"\n The reversed string is: \n";

   for(int i=0;i<=c.length();i++)
   {
       cout<<s.pop();


   }
   
}


String Reverse Program

write a c++ program to reverse a number

#include <iostream>
#include <list>
#include<cstdlib>
using namespace std;
int main()
{
list<int> integers;
for(int i = 0; i < 5; i++)
integers.push_front(i*i);

    for (std::list<int> :: iterator i = integers.begin(); i!=integers.end(); ++i)
    {
        cout<< *i << " ";
    }

}

String Reverse Program


No comments:
Write comments