98-7

原创 2016年08月28日 16:14:11
({[入栈 )}]于栈顶比较
<span style="font-size:14px;">#include <iostream>
#include <stdlib.h>
#include <stdbool.h>
using namespace std;
typedef struct node
{
    char c;
    struct node* pnext;
}qnode,*pnode;
typedef struct stack
{
    pnode top;
    pnode botton;
}qstack,*pstack;
bool empty(pstack s)
{
    if(s->top==s->botton)
        return true;
    else
        return false;
}
void init(pstack s)
{
    s->top=(pnode)malloc(sizeof(node));
    s->botton=s->top;
    s->botton->pnext=NULL;
}
void push(pstack s,char c_)
{
    pnode q;
    q=(pnode)malloc(sizeof(qnode));
    q->c=c_;
    q->pnext=s->top;
    s->top=q;
}
void pop(pstack s)
{
    char e;
    pnode temp;
    if(empty(s))
        cout<<"erro";
    else
    {
        e=s->top->c;
        temp=s->top;
        s->top=temp->pnext;
        free(temp);
    }
}
char gettop(pstack s)
{
    char e;
    e=s->top->c;
    return e;
}
int  length(pstack s)
{
    int i=0;
    pnode q;
    q=s->top;
    while(q!=s->botton)
    {
        i++;
        q=q->pnext;
    }
    return i;
}
int  judge(pstack s,char a[],int i)
{
    int j=0;
    char k;
    for(j=0;j<i;j++)
    {
        k=a[j];
        if(a[j]=='(' || a[j]=='{' || a[j]=='[')
        {
            push(s,a[j]);
        }
        else if(a[j]==')')
        {
            k=gettop(s);
            if(k=='(')
                pop(s);
            else
                return -1;
        }
        else if(a[j]==']')
        {
            k=gettop(s);
            if(k=='[')
                pop(s);
            else
                return -1;
        }
        else if(a[j]=='}')
        {
            k=gettop(s);
            if(k=='{')
                pop(s);
            else
                return -1;
        }
    }
    return length(s);
}
int main()
{
    int p;
    qstack s;
    char a[100];
    char ch;
    int i=0;
    while( ( ch = getchar() ) != '\n' )
    {
        a[i]=ch;
        i++;
    }
    init(&s);
    p=judge(&s,a,i);
    if(p==0)
        cout<<"yes";
    if(p>0)
        cout<<") ] }";
    if(p<0)
        cout<<"( [ {";
}</span>

版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

centOS7访问nginx失败解决-.0:80 failed (98: Address already in use)解决

前提:已经配置好静态IP 以防万一,先安装好iptables服务(不管你装没装,先执行,免得后面添乱) [root@localhost ~]# yum install iptables-service...

Incorrect string value: '\xE7\x94\x98\xE5\xB7\x9E...' for column 'SystemName' at row 1

org.springframework.jdbc.UncategorizedSQLException: ### Error updating database. Cause: java.sql.S...

8738声卡驱动(WIN7 XP 98)

  • 2011-10-01 15:26
  • 31.16MB
  • 下载

leetcode98---Validate Binary Search Tree

问题描述:Given a binary tree, determine if it is a valid binary search tree (BST).Assume a BST is define...

98主题可用于win7

  • 2014-03-17 20:43
  • 5.57MB
  • 下载

java.sql.SQLException: Incorrect string value: '\xF0\x9F\x98\xB3' for column 'Content' at row 1

在尝试将 emoji 表情符号 插入MySQL数据库时,遇到以下错误信息:### The error occurred while setting parameters ### SQL: INSERT...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)