标题:数组堆栈的宏?????
取消只看楼主
h1023417614
Rank: 4
等 级:禁止访问
帖 子:211
专家分:237
注 册:2012-11-30
结帖率:100%
已结贴  问题点数:30 回复次数:4 
数组堆栈的宏?????
程序代码:
#include<stdio.h>
#include<stdlib.h>
#include <assert.h>// 断言
//下面是数组堆栈的宏 函数依次是 判空 判满 压入 置顶 输出
#define generic_stack(stack_type,suffix,stack_size)        \
        static stack_type stack##suffix[stack_size];    \
        static int  top_element##suffix=-1;                 \
        int is_empty##suffix()                             \
        {                                                 \
           return top_element##suffix==-1;                 \
        }                                                  \
        void is_full##suffix()                              \
        {                                                   \
           return top_element##suffix==stack_size-1;         \
        }                                                    \
        int push##suffix(stack_type value)                     \
        {                                                     \
                assert(!is_full##suffix());                     \
               top_element##suffix+=1;                         \
         stack##suffix[top_element##suffix]=value;             \
        }                                                    \                            
        void pop##suffix()                                    \
        {                                                     \
                assert(!is_empty##suffix());                 \
               top_element##suffix-=1;                         \
        }                                                    \
        stack_type top##suffix()                            \
        {                                                    \    
               assert(!is_empty##suffix());                    \
              return stack##suffix[top_element##suffix];    \
        }                                                    
    



void main()
{
generic_stack(int,_int,10);
push_int(5);//输入5
push_int(10);
push_int(20);
    while(!is_empty_int())
    {
        printf("%d\n",top_int());//输出
        pop_int();
    }


}


通不过编译器啊!!!!!!!
搜索更多相关主题的帖子: static 
2013-01-30 20:26
h1023417614
Rank: 4
等 级:禁止访问
帖 子:211
专家分:237
注 册:2012-11-30
得分:0 
学习了额
2013-01-31 10:54
h1023417614
Rank: 4
等 级:禁止访问
帖 子:211
专家分:237
注 册:2012-11-30
得分:0 
顶起
2013-01-31 18:26
h1023417614
Rank: 4
等 级:禁止访问
帖 子:211
专家分:237
注 册:2012-11-30
得分:0 
1.有两个函数类型搞错了,
2.嵌套了函数。

改了还是没用,,,,,,不过感觉真的没啥好处,,暂时还是觉得模版行
2013-02-01 22:25
h1023417614
Rank: 4
等 级:禁止访问
帖 子:211
专家分:237
注 册:2012-11-30
得分:0 
发现了宏定义后面的\,这个符号后面必须马上回车,不能加任何一个字符,空格 tab都不行,,,,这里没做到啊


通过了
2013-02-01 22:37



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-397917-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.897692 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved