proplem in palindrome using stack

my code should check if the Entered string is a palindrome or not

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124

// stack.h
    typedef char comp;
    struct nodetype;
    typedef nodetype* nodeptr;
    class stack{
    public:
        stack();
        bool isfull()const;
        bool isempty()const;
        void push(comp elm);
        void pop(comp& elm);
        ~stack();
    private:
    nodeptr top;
    };
    /********************************************
    stack.cpp
    */
    #include<iostream>
    #include"stack.h"
    #include<cstddef>
    #include<cstdlib>
    #include<cstring>
    using namespace std;
    struct nodetype
    {
        comp data;
        nodeptr link;
    };
    stack::stack()
    {
    top=NULL;
    }
    bool stack::isempty()const
    {
    return top==NULL;
    }
    bool stack::isfull()const
    {
    nodeptr temp=new nodetype;
    return temp==NULL;
    }
    void stack::push(comp elm)
    {
    if(isfull())
        cout<<"No space ...!"<<endl;
    else
    {
    nodeptr newptr=new nodetype;
    newptr->data=elm;
    newptr->link=top;
    top=newptr;
    }
    }
    void stack::pop(comp& elm)
    {
    if(isempty())
    cout<<"NO DATA ...!"<<endl;
    else
    {
        nodeptr del=top;
        elm=top->data;
        top=top->link;
        delete del;
    }
    }
    stack::~stack()
    {
        nodeptr del;
    while(top!=NULL)
    {
    del=top;
    top=top->link;
    delete del;
    }
    }
    /**********************************
    client file
    */
    #include<iostream>
    #include"stack.h"
    #include<cstring>
    using namespace std;
    int main()
    {
    char str[6];
    char stcp[6];// to copy charachters from stack
    char ch;
    char ch2;// pop(ch2);
    stack s1;//new OBJ of stack
    cin.get(str,6);
    int i=0;
    while (str[i]!=NULL)
    {
    ch=str[i];
    s1.push(ch);
    i++;
    }
    for(int i=0;i<5;i++)
    {
        s1.pop(ch2);
        stcp[i]=ch2;
    }
    int j=0;
    bool ok=false;
    while(stcp[j]!=NULL)
    {
    if(stcp[j]==str[j])
        ok=true;
    else
        {
            ok=false;
            break;
    }
    j++;
    }
    if(ok)
        cout<<"palindrome"<<endl;
    else
        cout<<"Not palindrome"<<endl;
    system("pause");
    return 0;
    }

i think my proplem in char variable .....
thx Zaita

my proplem isn't with stack
but with c-string
i didn't know where the proplem......

Topic archived. No new replies allowed.