第十周技术博客

数据结构

二叉树遍历的学习

// 242陈坤鑫第十周.cpp : Defines the entry point for the console application.

//

 

#include "stdafx.h"

#include <stdio.h>

#include <stdlib.h>

typedef char DateType;

typedef struct Node{

         DateType data;

         struct Node *LChild,*RChild;

}*BiTree;

 

void PreOrder(BiTree root)

{

         if (root!=NULL)

         {

                   printf("%c",root->data);

                   PreOrder(root->LChild);

                   PreOrder(root->RChild);

         }

}

 

void InOrder(BiTree root)

{

         if (root!=NULL)

         {

                   InOrder(root->LChild);

                   printf("%c",root->data);

                   InOrder(root->RChild);

         }

}

 

void PostOrder(BiTree root)

{

         if (root!=NULL)

         {

                   PostOrder(root->LChild);

                   PostOrder(root->RChild);

                   printf("%c",root->data);

                  

         }

}

 

int main(int argc,char* argv[])

{

         printf("242 陈坤鑫 二叉树遍历\n");

         BiTree t[8];

         int i;

         for (i=1;i<=7;i++)

         {

                   t[i]=(BiTree)malloc(sizeof(*t[0]));

                   t[i]->data='A'+i-1;

                   t[i]->LChild=NULL;

                   t[i]->RChild=NULL;  

         }

         t[1]->LChild=t[2];t[1]->RChild=t[3];

         t[2]->LChild=t[4];//t[2]->RChild=t[5];

         t[3]->LChild=t[5];t[3]->RChild=t[6];

         t[4]->RChild=t[7];

         printf("前序遍历");

         PreOrder(t[1]);

         printf("\n");

 

         printf("中序遍历");

         PreOrder(t[1]);

         printf("\n");

 

         printf("后序遍历");

         PreOrder(t[1]);

         printf("\n");

         return 0;

}

 

 

父子结点的引用

// 242陈坤鑫第十周_2.cpp : Defines the entry point for the console application.

//

 

#include "stdafx.h"

#include <stdio.h>

#define Max 100

typedef char DataType;

typedef struct Trees{

         DataType datas[Max];

         int n;

}Trees;

#define  NoNode 0

 

void GetChildParent(Trees *t,DataType x){

         int i;

         for(i=1;i<=t->n;i++){

                   if(t->datas[i]==x)

                            break;

         }

         int(i>t->n){

                   printf("无此结点\n\n");return;

         }

         if(i==1){

                   printf("此结点%c为父结点,",x);

         }

         else printf("此结点%c的父结点为%c,",x,t->datas[i/2]);

         if(2*i<=t->n){

                   if(t->datas[i*2]!NoNode)

                            printf("左孩子结点为%c,",t->datas[i*2];

                   else printf("无左结点,");

         }

         else printf("无左结点,");

         if(2*i+1<=t->n){

                   if(t->datas[i*2+1]!=NoNode)

                            printf("右孩子结点为%c",t->datas[i*2+1]);

                   else printf("无右结点");

         }

         else printf("无右结点");

         printf("\n\n");

        

}

int mai(int argc,char* argv[])

{

         Trees;

         t.n=13;

         t.datas[4]=NoNode;t.datas[7]=NoNode;

         t.datas[8]=NoNode;t.datas[9]=NoNode;

         t.datas[11]=NoNode;t.datas[12]=NoNode;

         t.datas[1]='A';t.datas[2]='B';

         t.datas[3]='C';t.datas[5]='D';

         t.datas[6]='F';t.datas[10]='E';t.datas[13]='G';

                   char c[20];

                   while(true){

                            printf("请输入结点数据:");

                            scanf("%s",c);

                            if(c[0]=='0')break;

                   }

         return 0;

}

 

 

Web技术

键盘按键改变背景色

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>键盘按键改变背景色</title>

</head>

 

<body onkeypress="a()">

<script language="javascript">

function a()

{

         var n=window.event.keyCode

         switch(n)

         {

                   case 97:

                   document.bgColor="gray";break;

                   case 119:

                   document.bgColor="yellow";break;

         }

}

 

</script>

 

</body>

</html>

 

 

鼠标按键改变背景色

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>鼠标按键改变背景色</title>

</head>

 

<body>

<script language="javascript">

var color=new Array("red","yellow","blue");

var n=-1;

function mousedown(){

         document.bgColor="red";

         }

function mouseup(){

         document.bgColor="blue";

         }

</script>

<input type="button" name="change" value="变化背景颜色" onmousedown="mousedown()" onmouseup="mouseup()"/>

</body>

</html>

 

 

 

显示鼠标移动的位置

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>显示鼠标移动的位置</title>

</head>

 

<body>

<script language="javascript">

var x=0,y=0;

function MousePlace()

{

         x=window.event.x;

         y=window.event.y;

         window.status="X: "+x+"  "+" y: "+y+" ";

}

document.onmousemove=MousePlace;

</script>

</body>

</html>

周数

专业学习目标

专业学习时间

新增代码量

博客发表量

人文方面的学习

知识技能总结

 第十周

数据结构二叉树遍历和父子结点,Web技术鼠标键盘事件编程

5

400h

2

二叉树能够理解但在代码上无法很好的表现出来,web技术事件编程掌握良好

posted on 2016-05-08 18:40  废躯残骸  阅读(103)  评论(0编辑  收藏  举报