#include<bits/stdc++.h><br>
using namespace std;<br>
class stack
{
public:
int size;
int top;
char * arr;
};
int isempty(stack*ptr)<br>
{ if (ptr->top==-1)<br>
{<br>
return 1;<br>
}<br>
return 0;<br>
}<br>
int isFull(stack*ptr)<br>
{<br>
if (ptr->top==ptr->size-1)<br>
{<br>
return 1;<br>
}<br>
else<br>
{<br>
return 0;<br>
}<br>
}<br>
void push(stack*ptr,char value)<br>
{<br>
if(isFull(ptr))<br>
{<br>
cout<<"stack overflow";<br>
}<br>
else<br>
{<br>
ptr->top++;<br>
ptr->arr[ptr->top]=value;<br>
}<br>
}<br>
char pop(stack*ptr)<br>
{<br>
if(isempty(ptr))<br>
{<br>
cout<<"Stack is empty";<br>
return -1;<br>
}<br>
else<br>
{<br>
char v=ptr->arr[ptr->top];<br>
ptr->top--;<br>
return v;<br>
}<br>
}<br>
int peek(stack*ptr,int i)<br>
{<br>
if(ptr->top-i+1<0)<br>
{<br>
cout<<"invalid input";<br>
}<br>
else<br>
{<br>
return ptr->arr[ptr->top-i+1];<br>
}<br>
}<br>
int paranthesisamatch(char*exp)<br>
{ stack*ptr;<br>
ptr->size=100;<br>
ptr->top=-1;<br>
ptr->arr=(char *)malloc(ptr->size * sizeof(char));<br>
for (int i = 0;exp[i]!="\0"; i++)<br>
{<br>
if(exp[i]=='(')<br>
{<br>
push(ptr,'(');<br>
}<br>
else if (exp[i]==')')<br>
{<br>
if (isempty(ptr))<br>
{<br>
return 0;<br>
}<br>
pop(ptr);<br>
}<br>
{<br>
if (isempty(ptr))<br>
{<br>
return 1;<br>
}<br>
return 0;<br>
}<br>
int main()<br>
{<br>
char*exp= "8+(9*4)";<br>
if (paranthesisamatch(exp)))<br>
{<br>
cout<<"The paranthesis is matching";<br>
}<br>
cout<<"The paranthesis is not matching";<br>
return 0;<br>
};<br>
'Error'
C:\Users\91977\Desktop\C++>cd "c:\Users\91977\Desktop\C++\" && g++ tempCodeRunnerFile.cpp -o tempCodeRunnerFile && "c:\Users\91977\Desktop\C++\"tempCodeRunnerFile<br>
tempCodeRunnerFile.cpp:12:13: error: reference to 'stack' is ambiguous<br>
int isempty(stack*ptr)<br>
^~~~~<br>
tempCodeRunnerFile.cpp:3:7: note: candidates are: class stack<br>
class stack<br>
^~~~~<br>
In file included from c:\mingw\lib\gcc\mingw32\6.3.0\include\c++\stack:61:0, <br>
from c:\mingw\lib\gcc\mingw32\6.3.0\include\c++\mingw32\bits\stdc++.h:89, <br>
from tempCodeRunnerFile.cpp:1:<br>
c:\mingw\lib\gcc\mingw32\6.3.0\include\c++\bits\stl_stack.h:99:11: note: template<class <br>_Tp, class _Sequence> class std::stack<br>
class stack<br>
^~~~~<br>
tempCodeRunnerFile.cp:12:19: error: 'ptr' was not declared in this scope<br>
int isempty(stack*ptr)<br>
^~~<br>
Aucun commentaire:
Enregistrer un commentaire