正在加载图片...
private bool is Serial(intl a, intl, int n, ref string mystr) i int i=0,j=0; int st=new int MaxSize; /用作顺序栈 int top=-1; /用作栈顶指针 while(i<n &&j<n if(top==-1 top =bljD top++; st top]=ai; mysr+=元素"+a[ iToString+"进栈rn"; i++; else {mysr+="元素"+ sttop. ToString+"出栈rn top--;j++; while(top!=-1 & st[top==bljD) mystr+="元素"+ st top ToString0+"出栈rin"; top--;j++ if g-=n) return true; 是出栈序列时返回true else return false: 不是出栈序列时返回 falseprivate bool isSerial(int[] a,int[] b,int n,ref string mystr) { int i=0,j=0; int [] st=new int[MaxSize]; //用作顺序栈 int top=-1; //用作栈顶指针 while (i<n &&j<n) { if (top==-1 || st[top]!=b[j]) { top++; st[top]=a[i]; mystr+="元素"+a[i].ToString()+"进栈\r\n"; i++; } else { mystr+="元素"+st[top].ToString()+"出栈\r\n"; top--; j++; } } while (top!=-1 && st[top]==b[j]) { mystr+="元素"+st[top].ToString()+"出栈\r\n"; top--; j++; } if (j==n) return true; //是出栈序列时返回true else return false; //不是出栈序列时返回false }
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有