PDA: In computer science, a pushdown automaton (PDA) is a type of automaton that employs a stack. Pushdown automata are used in theories about what can be computed by machines. They are more capable than finite-state machines but less capable than Turing machines.*
*Reference: Wikipedia
Sample Code:
Q: Program For PDA Which Accpets Strings Of (0^n)(1^n)
Solution:
*Reference: Wikipedia
Sample Code:
Q: Program For PDA Which Accpets Strings Of (0^n)(1^n)
Solution:
#include<iostream> #include<string.h> using namespace std; int top; char s[10]; class Stack { public: void push(int x) { s[top++]=x; } void pop(int x) { s[top--]=x; } }; int main() { int i,n; char a[10]; cout<<"\nProgram For PDA Which Accpets Strings Of (0^n)(1^n)\n"; cout<<"\nEnter String::"; cin>>a; n=strlen(a); Stack st; top=-1; for(i=0;i<n;i++) { if(a[i]=='0' || a[i]=='1') { if(a[i]=='0') { st.push(a[i]); } else { st.pop(a[i]); } } else { break; } } if(top==-1) { cout<<"\nString Accepted.\n"; } else { cout<<"\nString Rejected.\n"; } return 0; }
it fails for 001101
ReplyDeleteAll 0's should come first and all 1's should come after 0's.
DeleteYou have entered incorrect string
this code is not showing any output just take input and terminate why?
ReplyDeletewhat about string 00010111
ReplyDelete110100 is Accepting here but it should reject actually
ReplyDeleteWrite a same program for PDA that accept well formed paranthesis
ReplyDelete