strcmp函数的用法问题
#include <stdio.h>#include <stdlib.h>
#include <string.h>
#include <conio.h>
//二叉树
typedef struct BiTreeNode
{
char book_name[20];
char writer[10];
int year;
struct BiTreeNode * lchild;
struct BiTreeNode * rchild;
}Book;
Book * InitBiTree()
{
Book * BookList;
BookList = (Book *)malloc(sizeof(Book));
strcpy(BookList->book_name,"");
strcpy(BookList->writer,"");
BookList->year=-1;
BookList->lchild=0;
BookList->rchild=0;
return BookList;
}
void Insert(Book * BookList, Book * newBook)
{
if (strcmp(BookList->book_name,newBook->book_name)>0) //这里输入<就无显示了
{
if (BookList->lchild==0)
BookList->lchild=newBook;
else
Insert(BookList->lchild, newBook);//递归调用
}
else
{
if (BookList->rchild==0)
BookList->rchild=newBook;
else
Insert(BookList->rchild, newBook);//递归调用
}
}
void InOrder(Book * BookList)
{
if (BookList==0) return;
if (BookList->year!=-1)
{
InOrder(BookList->lchild);
printf("%s\t%s\t%d\n",BookList->book_name,
BookList->writer, BookList->year);
}
InOrder(BookList->rchild);
}
int main()
{
Book * BOOK=0;
Book * newBook=0;
BOOK=InitBiTree();
newBook = (Book *)malloc(sizeof(Book));
strcpy(newBook->book_name,"c#程序设计教程");
strcpy(newBook->writer,"李春葆");
newBook->year=2010;
newBook->lchild=0;
newBook->rchild=0;
Insert(BOOK, newBook);
printf("加入一本书以后:\n");
InOrder(BOOK);
printf("\n");
newBook = (Book *)malloc(sizeof(Book));
strcpy(newBook->book_name,"实用数据结构");
strcpy(newBook->writer,"陈明");
newBook->year=2009;
newBook->lchild=0;
newBook->rchild=0;
Insert(BOOK, newBook);
printf("加入一本书以后:\n");
InOrder(BOOK);
printf("\n");
newBook = (Book *)malloc(sizeof(Book));
strcpy(newBook->book_name,"应用数学");
strcpy(newBook->writer,"吴静");
newBook->year=2011;
newBook->lchild=0;
newBook->rchild=0;
Insert(BOOK, newBook);
printf("加入一本书以后:\n");
InOrder(BOOK);
printf("\n");
newBook = (Book *)malloc(sizeof(Book));
strcpy(newBook->book_name,"职业生涯规划");
strcpy(newBook->writer,"谢彩英");
newBook->year=2011;
newBook->lchild=0;
newBook->rchild=0;
Insert(BOOK, newBook);
printf("加入一本书以后:\n");
printf("书名\t\t作者\t出版年份\n");
InOrder(BOOK);
getch();
}
求解
[ 本帖最后由 lxh30907 于 2011-5-15 10:51 编辑 ]