c小问题,跪求跪求
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <assert.h>
int lowestBid;
// A Tree is a pointer to its root node
typedef struct treeRep *Tree;
typedef struct treeRep Node;
// A Tree is simply a pointer to its root node
// What we need to define here is the Node structure
struct treeRep {
int bid;
bool unique;
Node *left;
Node *right;
};
// Private function to create new Nodes
Node *newNode(int bid)
{
Node *n;
n = malloc(sizeof(struct treeRep));
assert(n != NULL);
n->bid = bid;
n->left = NULL;
n->right = NULL;
n->unique = true;
return n;
}
// Add a new bid into a Tree
Tree treeInsert(Tree t, int bid)
{
if (t == NULL){
t = newNode(bid);
if(bid < lowestBid){
lowestBid = bid;
printf("new lowest unique bid!");
} else {
printf("unique but not lowest");
}
}else {
int diff = bid - t->bid;
if (diff == 0){
t->unique = false; // already in Tree
printf("not unique");
}else if (diff < 0)
t->left = treeInsert(t->left, bid);
else if (diff > 0)
t->right = treeInsert(t->right, bid);
}
return t;
}
int main(int argc, char **argv)
{
int bid;
Tree t = NULL;
while(scanf("%d",&bid) == 1){
printf("Bid of %d",bid);
treeInsert(t,bid);
printf(" [best bid: %d]\n",lowestBid);
}
exit(0);
}
-bash-3.2$ gcc -Wall -Werror -o lowestUniqueBid lowestUniqueBid.c
lowestUniqueBid.c:17: error: expected specifier-qualifier-list before 'bool'
lowestUniqueBid.c: In function 'newNode':
lowestUniqueBid.c:29: error: 'Node' has no member named 'left'
lowestUniqueBid.c:30: error: 'Node' has no member named 'right'
lowestUniqueBid.c:31: error: 'Node' has no member named 'unique'
lowestUniqueBid.c:31: error: 'true' undeclared (first use in this function)
lowestUniqueBid.c:31: error: (Each undeclared identifier is reported only once
lowestUniqueBid.c:31: error: for each function it appears in.)
lowestUniqueBid.c: In function 'treeInsert':
lowestUniqueBid.c:50: error: 'struct treeRep' has no member named 'unique'
lowestUniqueBid.c:50: error: 'false' undeclared (first use in this function)
lowestUniqueBid.c:53: error: 'struct treeRep' has no member named 'left'
lowestUniqueBid.c:53: error: 'struct treeRep' has no member named 'left'
lowestUniqueBid.c:55: error: 'struct treeRep' has no member named 'right'
lowestUniqueBid.c:55: error: 'struct treeRep' has no member named 'right'
-bash-3.2$