#include<stdio.h>
#include<limits.h>
#include<stdlib.h>
double add(double a, double b){ return a + b; }
double mal(double a, double b){ return a * b; }
double minus(double a, double b){ return a - b; }
double divid(double a, double b){ return a / b; }
typedef double (*funcp)(double, double);
typedef struct node_t{
char op;
funcp fn;
struct node_t *next;
} Node;
Node* new_node(char c, funcp fn)
{
Node
* ret
= (Node
*)malloc(sizeof(Node
)); ret->op = c;
ret->fn = fn;
ret->next = NULL;
return ret;
}
Node* add_node(Node *head, char c, funcp fn)
{
Node *next= new_node(c,fn);
Node *idx = head;
while(idx->next) idx = idx->next;
idx->next = next;
return head;
}
Node* search(Node *node, const char c)
{
if (!node){ return NULL;}
else if(c == node->op){ return node;}
else { return search( node->next, c );}
}
int main()
{
char d = '*';
double val;
Node *head = new_node(' ',NULL);
add_node(head, '+', add);
add_node(head, '*', mal);
add_node(head, '-', minus);
add_node(head, '/', divid);
val = search(head, d)->fn(6,9);
return 0;
}
I2luY2x1ZGU8c3RkaW8uaD4KI2luY2x1ZGU8bGltaXRzLmg+CiNpbmNsdWRlPHN0ZGxpYi5oPgoKZG91YmxlIGFkZChkb3VibGUgYSwgZG91YmxlIGIpeyByZXR1cm4gYSArIGI7IH0KZG91YmxlIG1hbChkb3VibGUgYSwgZG91YmxlIGIpeyByZXR1cm4gYSAqIGI7IH0KZG91YmxlIG1pbnVzKGRvdWJsZSBhLCBkb3VibGUgYil7IHJldHVybiBhIC0gYjsgfQpkb3VibGUgZGl2aWQoZG91YmxlIGEsIGRvdWJsZSBiKXsgcmV0dXJuIGEgLyBiOyB9Cgp0eXBlZGVmIGRvdWJsZSAoKmZ1bmNwKShkb3VibGUsIGRvdWJsZSk7CnR5cGVkZWYgc3RydWN0IG5vZGVfdHsKCWNoYXIgb3A7CglmdW5jcCBmbjsKCXN0cnVjdCBub2RlX3QgKm5leHQ7Cn0gTm9kZTsKCgpOb2RlKiBuZXdfbm9kZShjaGFyIGMsIGZ1bmNwIGZuKQp7CglOb2RlKiByZXQgPSAoTm9kZ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