I got it finally. Here my final code if anybody wants to check it out:
Code:
#include <iostream>
#include <string>
using namespace std;
const int DefaultListSize = 50;
typedef char Elem;
class Astack
{
private:
int top; /*Index for top element*/
int size; /*Maximum size of stack*/
Elem*listArray; /*Array holding stack elements*/
public:
Astack(int sz =DefaultListSize) /*Constructor*/
{size = sz; top = 0; listArray = new Elem[sz];}
~Astack() { delete [] listArray;} /*Destructor*/
void clear() {top = 0;}
bool push(const Elem& item){
if(top == size) return false; /* Stack is full*/
else {listArray [top++] = item;
return true;
}
}
bool pop(Elem& item){ /*Pop top element*/
if(top == 0) return false;
else {item = listArray[--top];
return true;
}
}
bool topValue(Elem& item) const { /*Return top element*/
if (top == 0) return false;
else {item = listArray[top - 1];
return true;
}
}
int length() const {return top;}
bool IsEmpty() const {if(top == 0) return true;
else return false;
}
};
bool Opener(char ch){
if((ch == '(') || (ch =='[') || (ch =='{'))
return true;
else
return false;
}/*end of opener*/
bool Match(char Lc, char Rc){
if(( Lc == '(') && (Rc == ')') || ((Lc == '[') && (Rc == ']')) ||((Lc == '{') && (Rc == '}')))
return true;
else
return false;
}/*end of Match*/
bool Closer(char ch){
if((ch == ')') || (ch == ']') || (ch == '}'))
return true;
else
return false;
}/*end of closer*/
int main(){
Astack S;
string s;
unsigned int i;
char a;
cout <<"Enter data:\n";
getline(cin, s);
for(i = 0; i < s.length(); i++){
if(Opener(s.at(i)))
S.push(s.at(i));
else if(Closer(s.at(i))){
if(S.IsEmpty()){
cout << "Found a Closing bracket before an Opening bracket or\n There are no Opening brackets or\n There's an extra Closing bracket";
cout << "\nGrouping symbols not used properly";
return 0;
}
else
S.pop(a);
if(!Match(a, s.at(i))){
cout << "No matching bracket\n";
cout << "Grouping symbols not used properly";
return 0;
}
}
}
if(!S.IsEmpty()){
cout << "There's still an Opening bracket\n";
cout << "Grouping symbols not used properly";
}
else
cout << "Grouping symbols were used properly";
return 0;
}