使用链表打印真值表的 C 程序

问题描述

这是我构建的程序:

int mynand(int a,int b);
int mynor(int a,int b);
int myxor(int a,int b);
int report(CallBack f,char *gates);
int main( )
{
    CallBack myfunctions[] = {myand,myor,myxor,mynand,mynor};
    char gatename[N][9+1] = {"AndGate","OrGate","XorGate","NandGate","NorGate"};
    int i;
    int size = sizeof(myfunctions)/sizeof(CallBack);
    Name temp[N];

    for(i=0; i<size; i++)
    {
        strcpy(temp[i].gates,gatename[i]);
        temp[i].gatename=myfunctions[i];
    }

    for(i=0; i<size; i++)
    {
        printf("\n%s\n",temp[i].gates);
        report(temp[i].gatename,temp[i].gates);
    }


    return 0;
}
int myand (int a,int b)
{
    return a * b;
}

int myor (int a,int b)
{
    return a + b>0;
}

int mynand (int a,int b)
{
    return !(a * b);
}

int mynor (int a,int b)
{
    return !(a + b);
}

int myxor (int a,int b)
{
    return a*(!(a*b)) + b*(!(a*b));
}

int report(CallBack f,char * gates)
{
    int i,j;

    for(i=0; i<2; i++)
    {
        for(j=0; j<2; j++)
        {
           printf("%d %d %d\n",i,j,f(i,j));
        }
    }
        printf("\n");

    return 0;
}

这个程序作为输出:

AND     
0 0 0      
0 1 0     
1 0 0                 
1 1 1


OR     
0 0 0       
0 1 1          
1 0 1           
1 1 1


XOR              
0 0 0               
0 1 1           
1 0 1               
1 1 0


NAND            
0 0 1                
0 1 1                
1 0 1              
1 1 0


NOR              
0 0 1                  
0 1 0                      
1 0 0              
1 1 0

2)我想修改函数 myand,myor 等,以便将输入的简单链表作为数据元素类型,并通过编写正确的代码证明它可以正常工作在主要。这里给出的语句:


typedef struct data {

int value;

struct data * next; }                    
Data;                                
typedef Data * DataList;                                     
int myandlst(DataList );                        
Data * createData( int value) {                    
Data * dataptr;                            
dataptr = malloc(sizeof (Data)); dataptr->value = value;                         
dataptr->next = NULL;                                   
return dataptr;
}

void appendData(DataList *lstptr,Data *newptr) {                             
if (*lstptr==NULL) {                                      
*lstptr = newptr;                              
return;               
}

appendData( &((*lstptr)->next),newptr);

return;
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...