新网创想网站建设,新征程启航

为企业提供网站建设、域名注册、服务器等服务

小代码栈之合法性一点思路不一样的际遇

/************
1 2 3 4 如栈
出栈 
3 2 4 1 返回0
错误 3 1 2 4 返回-1
**********/
#include
#include
#include

using namespace std;

bool judge(const char *push_seq, const char *pop_seq)
{
    if (NULL == push_seq || NULL == pop_seq)
    {
        return false;         
    }
    if (strlen(push_seq) != strlen(pop_seq))
    {
        return false;
    }
   
    stacksc;
    while (*push_seq)
    {
        if (0 == sc.size() || sc.top() != *pop_seq)
        { 
            sc.push(*push_seq++); //
        }
        else
        { 
            sc.pop();
            ++pop_seq; //
        }
    }
    while (sc.size())
    {
        if (sc.top() != *pop_seq++)
        {
            return false;
        }
        sc.pop();
    }
    
    return true;
}  
int mycheck1(int a[],int n)
{
    stacks;
    int i,j,k=1;          // 3 2 4 1
    for(i=0;ik)
          { for(j=k;js;      s.push(0);
    int i,j,k=1;         //BUG段  经过分析 在于s.top段  因为没有元素时这样做有越界的含义
    for(i=0;ik)
          { for(j=k;j            
            
                            
网站标题:小代码栈之合法性一点思路不一样的际遇
链接URL:http://www.wjwzjz.com/article/jdsscg.html
在线咨询
服务热线
服务热线:028-86922220
TOP