您的位置:首页 > 其它

第九周技术博客

2016-04-21 23:36 204 查看
我总结一下把 其实这两周实践真的很多

1.Java 学习了集合里面的

  HashSet  学会了写hashCode()来方便HashSet对于重复元素的判断

  ArrayList  学会了使用方法 顺便学了Iterator迭代器的使用

  TreeSet  如何使用Comparable和Comparator接口来完成自动排序

学习了泛型类,泛型的基本使用方法

一共应该才200+行代码

2.HTML

  帮忙同学们改改代码,自己做了小游戏什么的,多多少少1000行出头的代码把

  几天把半学期甚至更多的知识学完了

  可惜的是扫雷的算法没有写完整,有小bug

  打地鼠基本完美

3.英语6级单词最近有点放松,应该继续努力,程序员英语需要很好才对!感觉接下来的四级稳稳的

4.数据结构我不喜欢老师写一半我们写一半的上机方式,我通常是自己写所有代码,甚至加入一点我觉得有必要的功能,来增加安全性。

  接下来我还是发我觉得比较满意的代码把 就是这个子父节点的,可以选择在某个数据的节点加入子节点,不可以删除有兄弟节点,或者子节点、

  这下在写博客的时候觉得有点可以改进 也就是有兄弟节点也可以删除 不然不符合情理,不过更改不难。

  附上测试图

// BineryTree.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "stdlib.h"
#include "stdio.h"

typedef char datatype;

typedef struct BineryTree
{
BineryTree * firstchild;
BineryTree * sibling;
datatype data;
}BineryTree;

BineryTree* initTree(datatype data);
void myadd(BineryTree *a , datatype position, datatype data);
BineryTree * findPosition(BineryTree* a, datatype position);
int ifExist(BineryTree *a, datatype data);
void myDel(BineryTree* a,datatype position);

BineryTree * findPosition(BineryTree* a, datatype position)
{
if(a->data==position)
return a;
BineryTree* temp;
if(a->firstchild!=NULL)
{
temp=findPosition(a->firstchild,position);
if(temp!=NULL)
return temp;
}
if(a->sibling!=NULL)
{
temp=findPosition(a->sibling,position);
return temp;
}
return NULL;
}

/*如果存在函数*/
int ifExist(BineryTree *a, datatype data)
{
if(a->data==data)
return 1;
int temp;
if(a->firstchild!=NULL)
{
temp=ifExist(a->firstchild,data);
if(temp!=0)
return temp;
}
if(a->sibling!=NULL)
{
temp=ifExist(a->sibling,data);
return temp;
}
return 0;

}

/*添加
@param *a 传进来一个结构体变量
@param position 要插入在什么数据里面
@param data 要传入的数据
未完成
*/
void myadd(BineryTree *a , datatype position, datatype data)
{

int e = ifExist(a,data);
if(e==1)
{
printf("所插入的数据已经存在\n");
return;
}

BineryTree* temp = findPosition(a,position);
if(temp==NULL)
{
printf("没有可插入的位置\n");
return;
}
if(temp->firstchild==NULL)
{
temp->firstchild=initTree(data);
printf("成功插入数据%c\n",data);
}
else
{
temp=temp->firstchild;
while(temp->sibling!=NULL){temp=temp->sibling;}
temp->sibling=initTree(data);
printf("成功插入数据%c\n",data);
}
}

void myDel(BineryTree* a,datatype position)
{
int e = ifExist(a,position);
if(e==0)
{
printf("没有可删除的数据\n");
return;
}
BineryTree * temp = findPosition(a,position);
if(temp->firstchild!=NULL || temp->sibling!=NULL)
{
printf("不能删除因为有子节点或者兄弟节点\n");
return;
}
printf("成功删除数据%c\n",position);

free(a);
}

BineryTree* initTree(datatype data)
{
BineryTree* temp = (BineryTree *)malloc(sizeof(BineryTree));
temp->firstchild=NULL;
temp->sibling=NULL;
temp->data=data;
return temp;
}

void main(int argc, char* argv[])
{
BineryTree * mytree = initTree('A');
myadd(mytree,'A','B');
myadd(mytree,'B','B');
myadd(mytree,'B','D');
myadd(mytree,'B','F');
myadd(mytree,'G','L');
myDel(mytree,'B');
myDel(mytree,'F');

}


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: