• <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>
  • 檢測程序符號平衡的程序

    發表于:2007-05-26來源:作者:點擊數: 標簽:
    檢測程序符號平衡的程序,我用了一天的時間才搞好的。目前比較簡單 只能檢測()[]{}的符號缺失。 #include stdio.h #include stdlib.h struct sta{ char a; struct sta *next; }; push(char c, struct sta **pp) { struct sta *new; new = malloc(sizeof(stru
    檢測程序符號平衡的程序,我用了一天的時間才搞好的。目前比較簡單 只能檢測()[]{}的符號缺失。

    #include <stdio.h>
    #include <stdlib.h>

    struct sta{
     char a;
     struct sta *next;
    };

    push(char c, struct sta **pp)
    {
     struct sta *new;
     new = malloc(sizeof(struct sta));
     new->a = c; 
     new->next = *pp;
     *pp = new;
    }

    pop(char c, struct sta **pp)
    {
     switch(c)
     {
      case ')':
       if((*pp)->a != '(')
        printf("error! lost \" %c... \"\n",(*pp)->a);
        break;
      case ']':
       if((*pp)->a != '[')
        printf("error! lost \" %c... \"\n",(*pp)->a);
        break;
      case '}':
       if((*pp)->a != '{')
        printf("error! lost \" %c... \"\n",(*pp)->a);
        break;
     }
     *pp = (*pp)->next;
    }

    main()
    {
     char c;
     struct sta *p;
     p = malloc(sizeof(struct sta));
     p->next = NULL;
     while((c = getc(stdin)) != EOF)
     {
      if(c == '(')
      {
       push(c, &p);
      } 
      else if(c == ')')
      {
       pop(c, &p);
      } 
      if(c == '[')
      {
       push(c, &p);
      }
      else if(c == ']')
      {
       pop(c, &p);
      }
      if(c == '{')
      {
       push(c, &p);
      }
      else if(c == '}')
      {
       pop(c, &p);
      }
     }
    }

    原文轉自:http://www.kjueaiud.com

    評論列表(網友評論僅供網友表達個人看法,并不表明本站同意其觀點或證實其描述)
    老湿亚洲永久精品ww47香蕉图片_日韩欧美中文字幕北美法律_国产AV永久无码天堂影院_久久婷婷综合色丁香五月

  • <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>