#include
#include
#include
#include
#include
//定义二叉树节点数据结构
typedef
struct
node{
struct
node
*lchild;
char
data;
struct
node
*rchild;
}bitnode,*bitree;
//构造截取子串函数,start从零开始.
char
*get_substr(char
*strDest,int
start,int
end)
{
if(start>end)
return
NULL;
//如果左子树或右子树为空则返回空串
char
*strSub;
//字串指针
strSub=(char*)malloc((end-start+2)*sizeof(char));
int
i;
for(i=start;i<=end;i++)
strSub[i-start]=strDest[i];
strSub[end-start+1]='\0';
return
strSub;
}
//前序遍历二叉树,并输出
void
preorder_traverse(bitree
bt){
if(bt
!=
NULL)
{
printf("%c",bt->data);
preorder_traverse(bt->lchild);
preorder_traverse(bt->rchild);
}
}
//根据中序和后序遍历结果递归构造二叉树,并返回根指针
bitree
create_bitree(char
*inorder,char
*postorder)
//inorder和postoeder分别为中序和后序遍历的结果字符串
{
if(inorder==NULL
||
postorder==NULL)
return
NULL;
//空串则返回空树
char
root_data;//根节点字符
char
*lchild_instr,*lchild_postr,*rchild_instr,*rchild_postr;//左子树和右子树中序及后序字符串
int
i,len;
len=strlen(inorder);
//中序和后序字符串长度相等
bitree
new_bitree=(bitree)malloc(sizeof(bitnode));
root_data=postorder[len-1];//树的根节点必然为中序遍历的最后一个字符
new_bitree->data=root_data;
for(i=0;i
{
if(inorder[i]==root_data)
break;
}
//确定左子树和右子树中序及后序字符串
lchild_instr=get_substr(inorder,0,i-1);
lchild_postr=get_substr(postorder,0,i-1);
rchild_instr=get_substr(inorder,i+1,len-1);
rchild_postr=get_substr(postorder,i,len-2);
//递归构造子树
new_bitree->lchild=create_bitree(lchild_instr,lchild_postr);
new_bitree->rchild=create_bitree(rchild_instr,rchild_postr);
return
new_bitree;
}
void
main(){
char
inorder[20]="BDCEAFHG";
char
postorder[20]="DECBHGFA";
bitree
root;
root=create_bitree(inorder,postorder);
//输出前序遍历结果
printf("the
binary
tree
in
preorder
is:\n");
preorder_traverse(root);
_getch();
}
//满意的话别忘了多加点分哈
#include
struct mul
{
int real;
int image;
}f1,f2;
void main()
{
int a,b;
printf("input real and image:\n");
scanf("%d %d",&f1.real,&f1.image);
printf("\ninput real and image");
scanf("%d%d",&f2.real,&f2.image);
a=f1.real*f2.real-f1.image*f2.image;
b=f1.real*f2.image+f2.real*f1.image;
if(b>0)
printf("%d+%di\n",a,b);
else
printf("%d%di\n",a,b);
getchar();
}
#include"stdio.h"
void main()
{float a1,a2,b1,b2,c,d;
printf("shu ru a1,a2,b1,b2:");
scanf("%s&s&s&s",a1,a2,b1,b2);
c=a1*b1-a2*b2;
d=a1*b2+a2*b1;
printf("/n %s ",c);
printf("%s",d);
printf("i");
getchar();
getchar();
}
呃,这个很简单啊,不过太晚了,明天没人解答我再看吧