主頁 > 軟體設計 > 期末復習筆記——樹和二叉樹

期末復習筆記——樹和二叉樹

2021-12-07 11:15:53 軟體設計

一、樹

1,樹型結構

樹型結構是一種非線性結構,與之前的線性表,堆疊,佇列還有字串,陣列,廣義表不同,相比與之前一對一的線性結構,樹型結構展示為一對多的非線性結構,

2,樹的定義,術語,森林

太多了,不打了,,,直接二叉樹



二、二叉樹

二叉樹,這個樹比較重要,結構簡單,規律性強,普通樹也可以通過轉化為二叉樹進行運算,簡化步驟,其中運用二叉樹的演算法也有很多,像最優二叉樹哈夫曼樹,樹狀陣列,線段樹等等,都是在二叉樹上進行操作,



1.幾個性質

1,一個節點最多只用有兩個孩子,所以在二叉樹的第i層上至多有2^{i-1}個結點

2,深度為k的二叉樹至多有2^{k}-1個結點

3,對于任何一棵二叉樹T,如果其葉子樹為n{_0},度為2的結點數為n{_2},則n{_0}=n{_2}+1

咋算的

總邊數:

1,每個孩子和雙親都有一條連線,只有根沒有雙親,所以n個節點對于有n-1條邊,

2,再者總邊數還可以為度為2結點的邊和度為1節點的邊的和

所以n-1=n{_2}*2+n{_1}*1,又因為節點數等于度為2,度為1,度為0的n=n{_0}+n{_1}+n{_2} 帶入就為n{_0}=n{_2}+1

4,具有n個結點的完全二叉樹的深度為log _{2}{}^{n}+1

1,滿二叉樹:深度為k,且結點數為2^{k}-1的二叉樹

2,完全二叉樹:

我們可以聯想到到在排序那章講的堆排序,堆就是一個完全二叉樹,堆中的某個結點的值總 是大于等于(最大堆)或小于等于(最小堆)其孩子結點的值,第 k 層所有的結點都連續集中 在最左邊,

所以二叉樹的深度為k,除第 k 層外,其它各層 (1~k-1) 的結點數都達到最大個數,

第 k 層所有的結點都連續集中在最左邊,且其中每一個結點都能與滿二叉樹匹配的二叉樹.

2,二叉樹的存盤結構

學習了前面的佇列,堆疊,串等,思考存盤結構可以想到兩個方面:順序存盤,鏈式存盤

1,順序存盤

#define MAXTSIZE 100
typedef char SqbiTree[MAXTSIZE];
SqbiTree bt;


123456789101112
aebfdcgh

空的結點算上,12個結點,log{_2}{ }^{12}+1有四層

先畫出滿二叉樹,再填上去

2,鏈式存盤

重點還是看鏈式存盤,,,

typedef struct BiNode {
	char data;
	struct BiNode* lchild, * rchild;
}Binode,*BiTree;

還可以利用雙向鏈表改寫二叉鏈表的指標域為三叉鏈表,使其可以詢問結點的雙親結點

typedef struct BiNode {
	char data;
	struct BiNode* lchild, * rchild;
	struct BiNode* parent;
}Binode,*BiTree;

3,遍歷二叉樹

1,遍歷二叉樹的方法有六種

根左右,左根右,左右根,根右左,右根左,右左根

后三個和前三個對稱,所以只研究前三個

根左右先序(根)遍歷
左根右中序(根)遍歷
左右根后序(根)遍歷

思考:堆疊和佇列的前綴運算式,中綴運算式,后綴運算式,應該是由二叉樹的三種遍歷方式展現出來的

可以看出上次使用入堆疊操作也可以得到三種運算式的結果,猜測三種遍歷方式也可以使用堆疊進行實作,

1.1先根遍歷:訪問根結點——>左子樹——>右子樹

遞回實作:

void Preordertravers(BiTree T) {
	if (T == NULL)return ;
	else {
		cout << T->data;
		Preordertravers(T->lchild);
		Preordertravers(T->rchild);
	}
}

堆疊實作:思路和遞回一致,先將根壓入堆疊,然后左子樹一并壓入堆疊直到空為止開始彈堆疊,取堆疊頂結點判斷右子樹是否存在,如果存在繼續壓入左子樹操作,

void PrevOrder_stack(Binode* T)
{
	stack<Binode*> s;
	Binode*  Bi = T;
	while (Bi || !s.empty())
	{
		if(Bi)
		{
			cout << Bi->data;
			s.push(Bi);
			Bi = Bi->lchild;
		}
		else {
			Bi = s.top();
			s.pop();
			Bi = Bi->rchild;
		}
	}
	cout << "先序遍歷_堆疊" << endl;
}

1.2中根遍歷:訪問左子樹——>根結點——>右子樹

void Inordertraverse(BiTree T) {
	if (T == NULL)return;
	else {
	
		Inordertraverse(T->lchild);
		cout << T->data;
		Inordertraverse(T->rchild);
	}
}

堆疊實作:和先序差不多,左子樹壓入堆疊直到葉子開始彈堆疊并輸出,然后再將右子樹壓入堆疊中

void InOrder_stack(Binode* T)
{
	stack<Binode*> s;

	Binode* Bi = T;

	while (Bi || !s.empty())
	{
		if (Bi)
		{
			s.push(Bi);
			Bi = Bi->lchild;
		}
		else {
			Bi = s.top();
			cout << Bi->data;
			s.pop();
			Bi = Bi->rchild;
		}
	}
	cout << "中序遍歷_堆疊" << endl;
}

1.3后根遍歷:訪問左子樹——>右子樹——>根結點

void Postordertraverse(BiTree T) {
	if (T == NULL)return;
	else {

		Postordertraverse(T->lchild);
		Postordertraverse(T->rchild);
		cout << T->data;
	}
}

堆疊實作:也是先把左子樹壓入堆疊直到空,然后判斷是否存在右子樹,如果有用vis記錄該結點,然后開始重復上述操作,繼續將右子樹中的左子樹壓入堆疊,直到為葉子結點

void PastOrder_stack(Binode* T)
{
	Binode* Bi = T;
	Binode* vis = NULL;
	stack<Binode*> s;
	while (Bi||!s.empty())
	{
		if (Bi)
		{
			s.push(Bi);
			Bi = Bi->lchild;
		}
		else {
			Bi = s.top();
			if (Bi->rchild && vis != Bi->rchild)
				Bi = Bi->rchild;
			else if (( Bi->rchild==NULL) || (vis == Bi->rchild))
			{
				cout << Bi->data;
				vis = Bi;
				s.pop();
				Bi = NULL;
			}
		}
	}
	cout << "后序遍歷_堆疊" << endl;
}

1.4層次遍歷:

從上到下,從左到右

void HierarchyOrder(Binode * T)
{
	queue<Binode*>q;
	q.push(T);
	Binode* temp;
	while (!q.empty()) {
		temp = q.front();
		q.pop();
		cout << temp->data;
		if (temp->lchild != NULL) {
			q.push(temp->lchild);
		}
		if (temp->rchild != NULL) {
			q.push(temp->rchild);
		}
	}
}

2,二叉樹的創建和easyx的可視化操作

二叉樹的創建以先根遍歷的方式

void CreateBiTree(BiTree* T){
	char ch;
	cin >> ch;
	if (ch == '.') {
		*T = NULL;
	}
	else {
		*T = (BiTree)malloc(sizeof(Binode));
		(*T)->data = ch;
		CreateBiTree(&((*T)->lchild));
		CreateBiTree(&((*T)->rchild));
	}
}

用easyx首先畫一張圖,我想讓這棵樹的根節點從坐標(360,200)的位置開始生成根結點畫個圈,然后先從左子樹開始向他六十度方向連線并為當前結點畫個圈,直到左子樹為空,開始回溯,判斷是否有右子樹,有則向六十度方向畫出右子樹為當前結點畫個圈并重復上述畫左子樹的方法,

當然,因為二叉樹如果左子樹和右子樹的連線角度和線長都相等,這可以理解為一個對稱圖形,那么可能內側的結點會有重疊覆寫,所以,我將角度設為變數,每增加一層,角度x{_p}都除以2,對應的(x,y)到終點(xf,yf)的距離也縮短1.2倍

x{_f}=x\pm (x{_t}*\left |cos(x{_p}) \right |)/1.2

y{_f}=y\pm (x{_t}*\left |sin(y{_p}) \right |)/1.2

程式到這里也這里也只是畫了一張圖,最求高級的我想讓這份作業高級一點,把他變成影片:

線段細化為無數個點排列在一起,我通過兩點公式求出這條顯得函式關系式:y=\frac{y{_t}}{x{_t}}*x-\frac{y{_t}}{x{_t}}*x{_x{_0}}+y{_0}

之后我們將x到x{_f}細化為500份,y由公式可得,通過回圈遍歷每個點可得到生成線段的影片

void PrevOrderDraw(BiTree T, double x, double y, double xt, double yt,double xp,int time,int dep)//xp為角度,
{
	if (T)
	{
		setfillcolor(BLUE);
		setbkmode(TRANSPARENT);
		fillcircle(x, y, 20);
		outtextxy(x - 5, y - 5, T->data);
	}
	if (T->lchild)//左子樹
	{
		double i ,j;
		for (i = x,j=y; i >=x - xt,j<=y+yt;) {
			i -= (x - xt) / 500, j =(-yt/xt)*i-(-yt/xt)*x+y;
			line(x,y , i, j);
			Sleep(time);
		}
		setfillcolor(BLUE);
		setbkmode(TRANSPARENT);
		fillcircle(x, y, 20);
		outtextxy(x - 5, y - 5, T->data);
		PrevOrderDraw(T->lchild, x - xt, y + yt, xt / 1.2 * abs(cos(xp)), yt / 1.2 * abs(sin(xp)), xp / 2, time + 4 * dep, dep + 1);
	}
	
	if (T->rchild)//右子樹
	{
		double i, j;
		for (i = x, j = y; i >= x + xt, j <= y + yt;) {
			i += (x + xt) / 500, j = (yt / xt) * i - (yt / xt) * x + y;
			line(x, y, i, j);
			Sleep(time);
		}
		setfillcolor(BLUE);
		setbkmode(TRANSPARENT);
		fillcircle(x, y, 20);
		outtextxy(x - 5, y - 5, T->data);
		PrevOrderDraw(T->rchild, x + xt, y + yt, xt / 1.2 * abs(cos(xp)), yt / 1.2 * abs(sin(xp)), xp / 2, time + 4 * dep, dep + 1);
	}
}

void PrintBiTree(BiTree T)
{
	PrevOrderDraw(T, 360,200, 200* abs(sin(PI / 3)), 200* abs(cos(PI / 3)), PI / 3,6,1);
}

考慮到后面線段變短,所以每次睡眠時間通過層數增加,還有每次畫完線需要再畫一次圓蓋掉線的痕跡,不然影響美觀,

二叉樹AB.C..DE.G..F.H..先序遍歷生成影片結束的樣子

當然這只是一棵小二叉樹,對于5層以上的建議大家長度由短到長,角度由小到大,不會顯得太密集,

3,二叉樹的遍歷和easyx可視化

想法很簡單:分別在輸出值上加個結點顏色改變的函式,之前想過用圓變大變小來操作,但是變大變小完線會被蓋掉,這樣我們要重新畫線,代表了我們要訪問他的雙親結點的x,y,這樣需要用到之前說的三叉鏈表存盤,我懶,沒有實作,

注意一下,這里加了xy,所以畫二叉樹那也要更改一下:

typedef struct BiNode {
	char data;

	double x, y;
	struct BiNode* lchild, * rchild;
}Binode,*BiTree;

各種遍歷:

這個變色是閃三下,寫的有點暴力

void circhange(int x, int y, int data)
{
	settextcolor(BLACK);
	setfillcolor(YELLOW);
	setbkmode(TRANSPARENT);
	fillcircle(x, y, 20);
	outtextxy(x - 5, y - 5, data);
	Sleep(400);
	setfillcolor(BLUE);
	setbkmode(TRANSPARENT);
	fillcircle(x, y, 20);
	outtextxy(x - 5, y - 5, data);
	Sleep(400);
	setfillcolor(YELLOW);
	setbkmode(TRANSPARENT);
	fillcircle(x, y, 20);
	outtextxy(x - 5, y - 5, data);
	Sleep(400);
}

void Preordertravers(BiTree T) {
	if (T == NULL)return ;
	else {
		cout << T->data;
		circhange(T->x, T->y,T->data);
		Preordertravers(T->lchild);
		Preordertravers(T->rchild);
	}
}

void Inordertraverse(BiTree T) {
	if (T == NULL)return;
	else {
	
		Inordertraverse(T->lchild);
		cout << T->data;
		circhange(T->x, T->y, T->data);
		Inordertraverse(T->rchild);
	}
}

void Postordertraverse(BiTree T) {
	if (T == NULL)return;
	else {

		Postordertraverse(T->lchild);
		Postordertraverse(T->rchild);
		cout << T->data;
		circhange(T->x, T->y, T->data);
	}
}

void HierarchyOrder(Binode * T)
{
	queue<Binode*>q;
	q.push(T);
	Binode* temp;
	while (!q.empty()) {
		temp = q.front();
		q.pop();
		cout << temp->data;
		circhange(temp->x, temp->y, temp->data);
		if (temp->lchild != NULL) {
			q.push(temp->lchild);
		}
		if (temp->rchild != NULL) {
			q.push(temp->rchild);
		}
	}
}

測驗了一下,每個演算法沒啥問題,接下來就可以實作選擇功能的界面了

4,easyx設計操控界面

首先設定生產二叉樹視窗

在main中打開檔案,利用easyx的滑鼠讀取對四種二叉樹進行讀取并生成

int main() {
	initgraph(720, 720, EW_SHOWCONSOLE);
	ifstream file;
	BiTree T;
	file.open("test.txt");
	file >> s1 >> s2 >> s3 >> s4;
	showjpg();
	BeginBatchDraw();

	ExMessage msg;
	int x[5], y[5], w[5], h[5];
	x[0] = 260;
	y[0] = 100;
	w[0] = 200;
	h[0] = 50;
	setfillcolor(YELLOW);
	fillroundrect(x[0], y[0], x[0] + w[0], y[0] + h[0], 10, 10);
	botton_table(x[0], y[0], w[0], h[0], "Bitree_1");
	x[1] = 260;
	y[1] = 200;
	w[1] = 200;
	h[1] = 50;
	setfillcolor(YELLOW);
	fillroundrect(x[1], y[1], x[1] + w[1], y[1] + h[1], 10, 10);
	botton_table(x[0], y[0], w[0], h[0], "Bitree_2");
	x[2] = 260;
	y[2] = 300;
	w[2] = 200;
	h[2] = 50;
	setfillcolor(YELLOW);
	fillroundrect(x[2], y[2], x[2] + w[2], y[2] + h[2], 10, 10);
	botton_table(x[2], y[2], w[2], h[2], "Bitree_3");
	x[3] = 260;
	y[3] = 400;
	w[3] = 200;
	h[3] = 50;
	setfillcolor(YELLOW);
	fillroundrect(x[3], y[3], x[3] + w[3], y[3] + h[3], 10, 10);
	botton_table(x[3], y[3], w[3], h[3], "Bitree_4");
	x[4] = 260;
	y[4] = 500;
	w[4] = 200;
	h[4] = 50;
	setfillcolor(YELLOW);
	fillroundrect(x[4], y[4], x[4] + w[4], y[4] + h[4], 10, 10);
	botton_table(x[4], y[4], w[4], h[4], "退出");
	bool checkt = 0;
	while (1) {
		if (peekmessage(&msg, EM_MOUSE)) {
			switch (msg.message) {
			case WM_LBUTTONDOWN://點擊
				if (msg.x >= x[0] && msg.x <= x[0] + w[0]  && msg.y >= y[0]  && msg.y <= y[0] + h[0] ) 
				{

					s = s1;
					ip = 0;
					cleardevice();
					CreateBiTree(&T);
					PrintBiTree(T);
					Sleep(800);
					cleardevice();
					showjpg();
					Orderchoice(T);
				}
				if (msg.x >= x[1] && msg.x <= x[1] + w[1]  && msg.y >= y[1]  && msg.y <= y[1] + h[1] )
				{
					s = s2;
					ip = 0;
					cleardevice();
					CreateBiTree(&T);
					PrintBiTree(T);
					Sleep(800);
					cleardevice();
					showjpg();
					Orderchoice(T);
				}
				if (msg.x >= x[2]  && msg.x <= x[2] + w[2]  && msg.y >= y[2] && msg.y <= y[2] + h[2])
				{
					s = s3;
					ip = 0;
					cleardevice();
					CreateBiTree(&T);
					PrintBiTree(T);
					Sleep(800);
					cleardevice();
					showjpg();
					Orderchoice(T);
				}
				if (msg.x >= x[3] && msg.x <= x[3] + w[3] && msg.y >= y[3] && msg.y <= y[3] + h[3])
				{
					s = s4;
					ip = 0;
					CreateBiTree(&T);
					cleardevice();
					PrintBiTree(T);
					Sleep(800);
					cleardevice();
					showjpg();
					Orderchoice(T);
				}
				if (msg.x >= x[4] && msg.x <= x[4] + w[4] && msg.y >= y[4] && msg.y <= y[4] + h[4])
				{
					checkt = true;
				}
				FlushBatchDraw();
			case WM_MOUSEFIRST://移動
				if (msg.x >= x[0] && msg.x <= x[0] + w[0]  && msg.y >= y[0]  && msg.y <= y[0] + h[0]) 
				{
					setfillcolor(RED);
					fillroundrect(x[0], y[0], x[0] + w[0], y[0] + h[0], 10, 10);
					botton_table(x[0], y[0], w[0], h[0], "Bitree_1");
				}
				else {
					setfillcolor(YELLOW);
					fillroundrect(x[0], y[0], x[0] + w[0], y[0] + h[0], 10, 10);
					botton_table(x[0], y[0], w[0], h[0], "Bitree_1");
				}
				if (msg.x >= x[1]  && msg.x <= x[1] + w[1]  && msg.y >= y[1]  && msg.y <= y[1] + h[1]) {
					setfillcolor(RED);
					fillroundrect(x[1], y[1], x[1] + w[1], y[1] + h[1], 10, 10);
					botton_table(x[1], y[1], w[1], h[1], "Bitree_2");
				}
				else {
					setfillcolor(YELLOW);
					fillroundrect(x[1], y[1], x[1] + w[1], y[1] + h[1], 10, 10);
					botton_table(x[1], y[1], w[1], h[1], "Bitree_2");
				}
				if (msg.x >= x[2]  && msg.x <= x[2] + w[2]  && msg.y >= y[2]  && msg.y <= y[2] + h[2]) {
					setfillcolor(RED);
					fillroundrect(x[2], y[2], x[2] + w[2], y[2] + h[2], 10, 10);
					botton_table(x[2], y[2], w[2], h[2], "Bitree_3");
				}
				else {
					setfillcolor(YELLOW);
					fillroundrect(x[2], y[2], x[2] + w[2], y[2] + h[2], 10, 10);
					botton_table(x[2], y[2], w[2], h[2], "Bitree_3");
				}
				if (msg.x >= x[3] && msg.x <= x[3] + w[3] && msg.y >= y[3] && msg.y <= y[3] + h[3]) {
					setfillcolor(RED);
					fillroundrect(x[3], y[3], x[3] + w[3], y[3] + h[3], 10, 10);
					botton_table(x[3], y[3], w[3], h[3], "Bitree_4");
				}
				else {
					setfillcolor(YELLOW);
					fillroundrect(x[3], y[3], x[3] + w[3], y[3] + h[3], 10, 10);
					botton_table(x[3], y[3], w[3], h[3], "Bitree_4");
				}
				if (msg.x >= x[4] && msg.x <= x[4] + w[4] && msg.y >= y[4] && msg.y <= y[4] + h[4]) {
					setfillcolor(RED);
					fillroundrect(x[4], y[4], x[4] + w[4], y[4] + h[4], 10, 10);
					botton_table(x[4], y[4], w[4], h[4], "退出");
				}
				else {
					setfillcolor(YELLOW);
					fillroundrect(x[4], y[4], x[4] + w[4], y[4] + h[4], 10, 10);
					botton_table(x[4], y[4], w[4], h[4], "退出");
				}
			}
			EndBatchDraw();
		}
		if (checkt) {
			break;
		}
	}
	return 0;
}

再定義一個遍歷選擇函式,即選擇并生成完所示二叉樹,并選擇遍歷方式

void Orderchoice(BiTree T) {

	showjpg();
	BeginBatchDraw();

	ExMessage msg;
	int x[5], y[5], w[5], h[5];
	x[0] = 260;
	y[0] = 100;
	w[0] = 200;
	h[0] = 50;
	setfillcolor(YELLOW);
	fillroundrect(x[0], y[0], x[0] + w[0], y[0] + h[0], 10, 10);
	botton_table(x[0], y[0], w[0], h[0], "先序遍歷");
	x[1] = 260;
	y[1] = 200;
	w[1] = 200;
	h[1] = 50;
	setfillcolor(YELLOW);
	fillroundrect(x[1], y[1], x[1] + w[1], y[1] + h[1], 10, 10);
	botton_table(x[0], y[0], w[0], h[0], "中序遍歷");
	x[2] = 260;
	y[2] = 300;
	w[2] = 200;
	h[2] = 50;
	setfillcolor(YELLOW);
	fillroundrect(x[2], y[2], x[2] + w[2], y[2] + h[2], 10, 10);
	botton_table(x[2], y[2], w[2], h[2], "后序遍歷");
	x[3] = 260;
	y[3] = 400;
	w[3] = 200;
	h[3] = 50;
	setfillcolor(YELLOW);
	fillroundrect(x[3], y[3], x[3] + w[3], y[3] + h[3], 10, 10);
	botton_table(x[3], y[3], w[3], h[3], "層次遍歷");
	x[4] = 260;
	y[4] = 500;
	w[4] = 200;
	h[4] = 50;
	setfillcolor(YELLOW);
	fillroundrect(x[4], y[4], x[4] + w[4], y[4] + h[4], 10, 10);
	botton_table(x[4], y[4], w[4], h[4], "退出");
	bool checkt = 0;
	while (1) {
		if (peekmessage(&msg, EM_MOUSE)) {
			switch (msg.message) {
			case WM_LBUTTONDOWN://點擊
				if (msg.x >= x[0] && msg.x <= x[0] + w[0] && msg.y >= y[0] && msg.y <= y[0] + h[0])
				{
					cleardevice();
					Draw(T, 360, 200, 180 * abs(sin(PI / 3)), 180 * abs(cos(PI / 3)), PI / 3);
					Preordertravers(T);
					cleardevice();
					showjpg();
				
				}
				if (msg.x >= x[1] && msg.x <= x[1] + w[1] && msg.y >= y[1] && msg.y <= y[1] + h[1])
				{
					cleardevice();
					Draw(T, 360, 200, 180 * abs(sin(PI / 3)), 180 * abs(cos(PI / 3)), PI / 3);
					Inordertraverse(T);
					cleardevice();
					showjpg();
				}
				if (msg.x >= x[2] && msg.x <= x[2] + w[2] && msg.y >= y[2] && msg.y <= y[2] + h[2])
				{
					cleardevice();
					Draw(T, 360, 200, 180 * abs(sin(PI / 3)), 180 * abs(cos(PI / 3)), PI / 3);
					Postordertraverse(T);
					cleardevice();
					showjpg();
				}
				if (msg.x >= x[3] && msg.x <= x[3] + w[3] && msg.y >= y[3] && msg.y <= y[3] + h[3])
				{
					cleardevice();
					Draw(T, 360, 200, 180 * abs(sin(PI / 3)), 180 * abs(cos(PI / 3)), PI / 3);
					HierarchyOrder(T);
					cleardevice();
					showjpg();
				}
				if (msg.x >= x[4] && msg.x <= x[4] + w[4] && msg.y >= y[4] && msg.y <= y[4] + h[4])
				{
					checkt = true;
				}
				FlushBatchDraw();
			case WM_MOUSEFIRST://移動
				if (msg.x >= x[0] && msg.x <= x[0] + w[0] && msg.y >= y[0] && msg.y <= y[0] + h[0])
				{
					setfillcolor(RED);
					fillroundrect(x[0], y[0], x[0] + w[0], y[0] + h[0], 10, 10);
					botton_table(x[0], y[0], w[0], h[0], "先序遍歷");
				}
				else {
					setfillcolor(YELLOW);
					fillroundrect(x[0], y[0], x[0] + w[0], y[0] + h[0], 10, 10);
					botton_table(x[0], y[0], w[0], h[0], "先序遍歷");
				}
				if (msg.x >= x[1] && msg.x <= x[1] + w[1] && msg.y >= y[1] && msg.y <= y[1] + h[1]) {
					setfillcolor(RED);
					fillroundrect(x[1], y[1], x[1] + w[1], y[1] + h[1], 10, 10);
					botton_table(x[1], y[1], w[1], h[1], "中序遍歷");
				}
				else {
					setfillcolor(YELLOW);
					fillroundrect(x[1], y[1], x[1] + w[1], y[1] + h[1], 10, 10);
					botton_table(x[1], y[1], w[1], h[1], "中序遍歷");
				}
				if (msg.x >= x[2] && msg.x <= x[2] + w[2] && msg.y >= y[2] && msg.y <= y[2] + h[2]) {
					setfillcolor(RED);
					fillroundrect(x[2], y[2], x[2] + w[2], y[2] + h[2], 10, 10);
					botton_table(x[2], y[2], w[2], h[2], "后序遍歷");
				}
				else {
					setfillcolor(YELLOW);
					fillroundrect(x[2], y[2], x[2] + w[2], y[2] + h[2], 10, 10);
					botton_table(x[2], y[2], w[2], h[2], "后序遍歷");
				}
				if (msg.x >= x[3] && msg.x <= x[3] + w[3] && msg.y >= y[3] && msg.y <= y[3] + h[3]) {
					setfillcolor(RED);
					fillroundrect(x[3], y[3], x[3] + w[3], y[3] + h[3], 10, 10);
					botton_table(x[3], y[3], w[3], h[3], "層次遍歷");
				}
				else {
					setfillcolor(YELLOW);
					fillroundrect(x[3], y[3], x[3] + w[3], y[3] + h[3], 10, 10);
					botton_table(x[3], y[3], w[3], h[3], "層次遍歷");
				}
				if (msg.x >= x[4] && msg.x <= x[4] + w[4] && msg.y >= y[4] && msg.y <= y[4] + h[4]) {
					setfillcolor(RED);
					fillroundrect(x[4], y[4], x[4] + w[4], y[4] + h[4], 10, 10);
					botton_table(x[4], y[4], w[4], h[4], "退出");
				}
				else {
					setfillcolor(YELLOW);
					fillroundrect(x[4], y[4], x[4] + w[4], y[4] + h[4], 10, 10);
					botton_table(x[4], y[4], w[4], h[4], "退出");
				}

			}
			EndBatchDraw();
		}
		if (checkt) {
			break;
		}
	}
	return;
}

總程式

#include <graphics.h>
#include<iostream>
#include<easyx.h>
#include <cassert>
#include<Windows.h>
#include<bits/stdc++.h>
using namespace std;

#define PI 3.1415
typedef struct BiNode {
char data;

double x, y;
struct BiNode* lchild, * rchild;
struct BiNode* parent;
}Binode,*BiTree;
string s,s1, s2, s3, s4;


void botton_table(int x, int y, int w, int h, const char* text) {

settextcolor(RGB(0, 0, 0));
setbkmode(TRANSPARENT);
char text_[50];
strcmp(text_, text);
int tx = x + (w - textwidth(text)) / 2;
int ty = y + (h - textheight(text)) / 2;
outtextxy(tx, ty, text);
}

void showjpg() {
IMAGE img;
loadimage(&img, "./1.jpg", 720, 720);
putimage(0, 0, &img);

}

void circhange(int x, int y, int data)
{
settextcolor(BLACK);
setfillcolor(YELLOW);
setbkmode(TRANSPARENT);
fillcircle(x, y, 20);
outtextxy(x - 5, y - 5, data);
Sleep(400);
setfillcolor(BLUE);
setbkmode(TRANSPARENT);
fillcircle(x, y, 20);
outtextxy(x - 5, y - 5, data);
Sleep(400);
setfillcolor(YELLOW);
setbkmode(TRANSPARENT);
fillcircle(x, y, 20);
outtextxy(x - 5, y - 5, data);
Sleep(400);
}

void Preordertravers(BiTree T) {
if (T == NULL)return ;
else {
cout << T->data;
circhange(T->x, T->y,T->data);
Preordertravers(T->lchild);
Preordertravers(T->rchild);
}
}

void Inordertraverse(BiTree T) {
if (T == NULL)return;
else {

Inordertraverse(T->lchild);
cout << T->data;
circhange(T->x, T->y, T->data);
Inordertraverse(T->rchild);
}
}

void Postordertraverse(BiTree T) {
if (T == NULL)return;
else {

Postordertraverse(T->lchild);
Postordertraverse(T->rchild);
cout << T->data;
circhange(T->x, T->y, T->data);
}
}

void HierarchyOrder(Binode * T)
{
queue<Binode*>q;
q.push(T);
Binode* temp;
while (!q.empty()) {
temp = q.front();
q.pop();
cout << temp->data;
circhange(temp->x, temp->y, temp->data);
if (temp->lchild != NULL) {
q.push(temp->lchild);
}
if (temp->rchild != NULL) {
q.push(temp->rchild);
}
}
}
int ip ;
char ch;
void CreateBiTree(BiTree* T){

ch = s[ip++];
if (ch == '.') {
*T = NULL;
}
else {
*T = (BiTree)malloc(sizeof(Binode));
(*T)->data = ch;
CreateBiTree(&((*T)->lchild));
CreateBiTree(&((*T)->rchild));
}
}
void PrevOrder_stack(Binode* T)
{
stack<Binode*> s;
Binode* Bi = T;
while (Bi || !s.empty())
{
if(Bi)
{
cout << Bi->data;
s.push(Bi);
Bi = Bi->lchild;
}
else {
Bi = s.top();
s.pop();
Bi = Bi->rchild;
}
}
cout << "先序遍歷_堆疊" << endl;
}
void InOrder_stack(Binode* T)
{
stack<Binode*> s;

Binode* Bi = T;

while (Bi || !s.empty())
{
if (Bi)
{
s.push(Bi);
Bi = Bi->lchild;
}
else {
Bi = s.top();
cout << Bi->data;
s.pop();
Bi = Bi->rchild;
}
}
cout << "中序遍歷_堆疊" << endl;
}
void PastOrder_stack(Binode* T)
{
Binode* Bi = T;
Binode* vis = NULL;
stack<Binode*> s;
while (Bi||!s.empty())
{
if (Bi)
{
s.push(Bi);
Bi = Bi->lchild;
}
else {
Bi = s.top();
if (Bi->rchild && vis != Bi->rchild)
Bi = Bi->rchild;
else if (( Bi->rchild==NULL) || (vis == Bi->rchild))
{
cout << Bi->data;
vis = Bi;
s.pop();
Bi = NULL;
}
}
}
cout << "后序遍歷堆疊" << endl;
}

void PrevOrderDraw(BiTree T, double x, double y, double xt, double yt,double xp,int time,int dep)//xp為角度,
{
if (T)
{
T->x = x;
T->y = y;
setfillcolor(BLUE);
settextcolor(WHITE);
setbkmode(TRANSPARENT);
fillcircle(x, y, 20);
outtextxy(x - 5, y - 5, T->data);
}
if (T->lchild)//左子樹
{
double i ,j;
for (i = x,j=y; i >=x - xt,j<=y+yt;) {
i -= (x - xt) / 500, j =(-yt/xt)*i-(-yt/xt)*x+y;
line(x,y , i, j);
Sleep(time);
}
setfillcolor(BLUE);
setbkmode(TRANSPARENT);
fillcircle(x, y, 20);
settextcolor(WHITE);
T->x = x;
T->y = y;
outtextxy(x - 5, y - 5, T->data);
PrevOrderDraw(T->lchild, x - xt, y + yt, xt / 1.1 * abs(cos(xp)), yt / 1.1 * abs(sin(xp)), xp / 2, time + pow(7, dep), dep + 1);
}

if (T->rchild)//右子樹
{
double i, j;
for (i = x, j = y; i >= x + xt, j <= y + yt;) {
i += (x + xt) / 500, j = (yt / xt) * i - (yt / xt) * x + y;
line(x, y, i, j);
Sleep(time);
}
setfillcolor(BLUE);
setbkmode(TRANSPARENT);
fillcircle(x, y, 20);
T->x = x;
T->y = y;
settextcolor(WHITE);
outtextxy(x - 5, y - 5, T->data);
PrevOrderDraw(T->rchild, x + xt, y + yt, xt / 1.1 * abs(cos(xp)), yt / 1.1 * abs(sin(xp)), xp / 2, time + pow(7, dep), dep + 1);
}
}

void PrintBiTree(BiTree T)
{
PrevOrderDraw(T, 360,200, 180* abs(sin(PI / 3)), 180* abs(cos(PI / 3)), PI / 3,3,1);
}

void Draw(BiTree T, double x, double y, double xt, double yt, double xp)//xp為角度,
{
if (T)
{
T->x = x;
T->y = y;
setfillcolor(BLUE);
setbkmode(TRANSPARENT);
fillcircle(x, y, 20);
outtextxy(x - 5, y - 5, T->data);
}
if (T->lchild)//左子樹
{
line(x, y, x-xt,y+yt);
setfillcolor(BLUE);
setbkmode(TRANSPARENT);
fillcircle(x, y, 20);
T->x = x;
T->y = y;
outtextxy(x - 5, y - 5, T->data);
Draw(T->lchild, x - xt, y + yt, xt / 1.1 * abs(cos(xp)), yt / 1.1 * abs(sin(xp)), xp / 2);
}

if (T->rchild)//右子樹
{
line(x, y, x+xt,y+yt);
setfillcolor(BLUE);
setbkmode(TRANSPARENT);
fillcircle(x, y, 20);
T->x = x;
T->y = y;
outtextxy(x - 5, y - 5, T->data);
Draw(T->rchild, x + xt, y + yt, xt / 1.1 * abs(cos(xp)), yt / 1.1 * abs(sin(xp)), xp / 2);
}
}


//int main()
//{
// ifstream file;
// file.open("test.txt");
// file >> s1 >> s2 >> s3 >> s4;
// s = s1;
//
// BiTree T;
//
// CreateBiTree(&T,0);
//
// PrevOrder_stack(T);
// InOrder_stack(T);
// PastOrder_stack(T);
//
// PrintBiTree(T);
//
//
//
//
// HierarchyOrder(T);
// cout << "層次遍歷堆疊" << endl;
// Draw(T, 360, 200, 180 * abs(sin(PI / 3)), 180 * abs(cos(PI / 3)), PI / 3);
// /*Preordertravers(T);
// cout << "先序遍歷" << endl;
// Inordertraverse(T);
// cout << "中序遍歷" << endl;
// Postordertraverse(T);
// cout << "后序遍歷" << endl;*/
//
//
// Sleep(80000);
//}


void Orderchoice(BiTree T) {

showjpg();
BeginBatchDraw();

ExMessage msg;
int x[5], y[5], w[5], h[5];
x[0] = 260;
y[0] = 100;
w[0] = 200;
h[0] = 50;
setfillcolor(YELLOW);
fillroundrect(x[0], y[0], x[0] + w[0], y[0] + h[0], 10, 10);
botton_table(x[0], y[0], w[0], h[0], "先序遍歷");
x[1] = 260;
y[1] = 200;
w[1] = 200;
h[1] = 50;
setfillcolor(YELLOW);
fillroundrect(x[1], y[1], x[1] + w[1], y[1] + h[1], 10, 10);
botton_table(x[0], y[0], w[0], h[0], "中序遍歷");
x[2] = 260;
y[2] = 300;
w[2] = 200;
h[2] = 50;
setfillcolor(YELLOW);
fillroundrect(x[2], y[2], x[2] + w[2], y[2] + h[2], 10, 10);
botton_table(x[2], y[2], w[2], h[2], "后序遍歷");
x[3] = 260;
y[3] = 400;
w[3] = 200;
h[3] = 50;
setfillcolor(YELLOW);
fillroundrect(x[3], y[3], x[3] + w[3], y[3] + h[3], 10, 10);
botton_table(x[3], y[3], w[3], h[3], "層次遍歷");
x[4] = 260;
y[4] = 500;
w[4] = 200;
h[4] = 50;
setfillcolor(YELLOW);
fillroundrect(x[4], y[4], x[4] + w[4], y[4] + h[4], 10, 10);
botton_table(x[4], y[4], w[4], h[4], "退出");
bool checkt = 0;
while (1) {
if (peekmessage(&msg, EM_MOUSE)) {
switch (msg.message) {
case WM_LBUTTONDOWN://點擊
if (msg.x >= x[0] && msg.x <= x[0] + w[0] && msg.y >= y[0] && msg.y <= y[0] + h[0])
{
cleardevice();
Draw(T, 360, 200, 180 * abs(sin(PI / 3)), 180 * abs(cos(PI / 3)), PI / 3);
Preordertravers(T);
cleardevice();
showjpg();

}
if (msg.x >= x[1] && msg.x <= x[1] + w[1] && msg.y >= y[1] && msg.y <= y[1] + h[1])
{
cleardevice();
Draw(T, 360, 200, 180 * abs(sin(PI / 3)), 180 * abs(cos(PI / 3)), PI / 3);
Inordertraverse(T);
cleardevice();
showjpg();
}
if (msg.x >= x[2] && msg.x <= x[2] + w[2] && msg.y >= y[2] && msg.y <= y[2] + h[2])
{
cleardevice();
Draw(T, 360, 200, 180 * abs(sin(PI / 3)), 180 * abs(cos(PI / 3)), PI / 3);
Postordertraverse(T);
cleardevice();
showjpg();
}
if (msg.x >= x[3] && msg.x <= x[3] + w[3] && msg.y >= y[3] && msg.y <= y[3] + h[3])
{
cleardevice();
Draw(T, 360, 200, 180 * abs(sin(PI / 3)), 180 * abs(cos(PI / 3)), PI / 3);
HierarchyOrder(T);
cleardevice();
showjpg();
}
if (msg.x >= x[4] && msg.x <= x[4] + w[4] && msg.y >= y[4] && msg.y <= y[4] + h[4])
{
checkt = true;
}
FlushBatchDraw();
case WM_MOUSEFIRST://移動
if (msg.x >= x[0] && msg.x <= x[0] + w[0] && msg.y >= y[0] && msg.y <= y[0] + h[0])
{
setfillcolor(RED);
fillroundrect(x[0], y[0], x[0] + w[0], y[0] + h[0], 10, 10);
botton_table(x[0], y[0], w[0], h[0], "先序遍歷");
}
else {
setfillcolor(YELLOW);
fillroundrect(x[0], y[0], x[0] + w[0], y[0] + h[0], 10, 10);
botton_table(x[0], y[0], w[0], h[0], "先序遍歷");
}
if (msg.x >= x[1] && msg.x <= x[1] + w[1] && msg.y >= y[1] && msg.y <= y[1] + h[1]) {
setfillcolor(RED);
fillroundrect(x[1], y[1], x[1] + w[1], y[1] + h[1], 10, 10);
botton_table(x[1], y[1], w[1], h[1], "中序遍歷");
}
else {
setfillcolor(YELLOW);
fillroundrect(x[1], y[1], x[1] + w[1], y[1] + h[1], 10, 10);
botton_table(x[1], y[1], w[1], h[1], "中序遍歷");
}
if (msg.x >= x[2] && msg.x <= x[2] + w[2] && msg.y >= y[2] && msg.y <= y[2] + h[2]) {
setfillcolor(RED);
fillroundrect(x[2], y[2], x[2] + w[2], y[2] + h[2], 10, 10);
botton_table(x[2], y[2], w[2], h[2], "后序遍歷");
}
else {
setfillcolor(YELLOW);
fillroundrect(x[2], y[2], x[2] + w[2], y[2] + h[2], 10, 10);
botton_table(x[2], y[2], w[2], h[2], "后序遍歷");
}
if (msg.x >= x[3] && msg.x <= x[3] + w[3] && msg.y >= y[3] && msg.y <= y[3] + h[3]) {
setfillcolor(RED);
fillroundrect(x[3], y[3], x[3] + w[3], y[3] + h[3], 10, 10);
botton_table(x[3], y[3], w[3], h[3], "層次遍歷");
}
else {
setfillcolor(YELLOW);
fillroundrect(x[3], y[3], x[3] + w[3], y[3] + h[3], 10, 10);
botton_table(x[3], y[3], w[3], h[3], "層次遍歷");
}
if (msg.x >= x[4] && msg.x <= x[4] + w[4] && msg.y >= y[4] && msg.y <= y[4] + h[4]) {
setfillcolor(RED);
fillroundrect(x[4], y[4], x[4] + w[4], y[4] + h[4], 10, 10);
botton_table(x[4], y[4], w[4], h[4], "退出");
}
else {
setfillcolor(YELLOW);
fillroundrect(x[4], y[4], x[4] + w[4], y[4] + h[4], 10, 10);
botton_table(x[4], y[4], w[4], h[4], "退出");
}

}
EndBatchDraw();
}
if (checkt) {
break;
}
}
return;
}

int main() {
initgraph(720, 720, EW_SHOWCONSOLE);
ifstream file;
BiTree T;
file.open("test.txt");
file >> s1 >> s2 >> s3 >> s4;
showjpg();
BeginBatchDraw();

ExMessage msg;
int x[5], y[5], w[5], h[5];
x[0] = 260;
y[0] = 100;
w[0] = 200;
h[0] = 50;
setfillcolor(YELLOW);
fillroundrect(x[0], y[0], x[0] + w[0], y[0] + h[0], 10, 10);
botton_table(x[0], y[0], w[0], h[0], "Bitree_1");
x[1] = 260;
y[1] = 200;
w[1] = 200;
h[1] = 50;
setfillcolor(YELLOW);
fillroundrect(x[1], y[1], x[1] + w[1], y[1] + h[1], 10, 10);
botton_table(x[0], y[0], w[0], h[0], "Bitree_2");
x[2] = 260;
y[2] = 300;
w[2] = 200;
h[2] = 50;
setfillcolor(YELLOW);
fillroundrect(x[2], y[2], x[2] + w[2], y[2] + h[2], 10, 10);
botton_table(x[2], y[2], w[2], h[2], "Bitree_3");
x[3] = 260;
y[3] = 400;
w[3] = 200;
h[3] = 50;
setfillcolor(YELLOW);
fillroundrect(x[3], y[3], x[3] + w[3], y[3] + h[3], 10, 10);
botton_table(x[3], y[3], w[3], h[3], "Bitree_4");
x[4] = 260;
y[4] = 500;
w[4] = 200;
h[4] = 50;
setfillcolor(YELLOW);
fillroundrect(x[4], y[4], x[4] + w[4], y[4] + h[4], 10, 10);
botton_table(x[4], y[4], w[4], h[4], "退出");
bool checkt = 0;
while (1) {
if (peekmessage(&msg, EM_MOUSE)) {
switch (msg.message) {
case WM_LBUTTONDOWN://點擊
if (msg.x >= x[0] && msg.x <= x[0] + w[0] && msg.y >= y[0] && msg.y <= y[0] + h[0] )
{

s = s1;
ip = 0;
cleardevice();
CreateBiTree(&T);
PrintBiTree(T);
Sleep(800);
cleardevice();
showjpg();
Orderchoice(T);
}
if (msg.x >= x[1] && msg.x <= x[1] + w[1] && msg.y >= y[1] && msg.y <= y[1] + h[1] )
{
s = s2;
ip = 0;
cleardevice();
CreateBiTree(&T);
PrintBiTree(T);
Sleep(800);
cleardevice();
showjpg();
Orderchoice(T);
}
if (msg.x >= x[2] && msg.x <= x[2] + w[2] && msg.y >= y[2] && msg.y <= y[2] + h[2])
{
s = s3;
ip = 0;
cleardevice();
CreateBiTree(&T);
PrintBiTree(T);
Sleep(800);
cleardevice();
showjpg();
Orderchoice(T);
}
if (msg.x >= x[3] && msg.x <= x[3] + w[3] && msg.y >= y[3] && msg.y <= y[3] + h[3])
{
s = s4;
ip = 0;
CreateBiTree(&T);
cleardevice();
PrintBiTree(T);
Sleep(800);
cleardevice();
showjpg();
Orderchoice(T);
}
if (msg.x >= x[4] && msg.x <= x[4] + w[4] && msg.y >= y[4] && msg.y <= y[4] + h[4])
{
checkt = true;
}
FlushBatchDraw();
case WM_MOUSEFIRST://移動
if (msg.x >= x[0] && msg.x <= x[0] + w[0] && msg.y >= y[0] && msg.y <= y[0] + h[0])
{
setfillcolor(RED);
fillroundrect(x[0], y[0], x[0] + w[0], y[0] + h[0], 10, 10);
botton_table(x[0], y[0], w[0], h[0], "Bitree_1");
}
else {
setfillcolor(YELLOW);
fillroundrect(x[0], y[0], x[0] + w[0], y[0] + h[0], 10, 10);
botton_table(x[0], y[0], w[0], h[0], "Bitree_1");
}
if (msg.x >= x[1] && msg.x <= x[1] + w[1] && msg.y >= y[1] && msg.y <= y[1] + h[1]) {
setfillcolor(RED);
fillroundrect(x[1], y[1], x[1] + w[1], y[1] + h[1], 10, 10);
botton_table(x[1], y[1], w[1], h[1], "Bitree_2");
}
else {
setfillcolor(YELLOW);
fillroundrect(x[1], y[1], x[1] + w[1], y[1] + h[1], 10, 10);
botton_table(x[1], y[1], w[1], h[1], "Bitree_2");
}
if (msg.x >= x[2] && msg.x <= x[2] + w[2] && msg.y >= y[2] && msg.y <= y[2] + h[2]) {
setfillcolor(RED);
fillroundrect(x[2], y[2], x[2] + w[2], y[2] + h[2], 10, 10);
botton_table(x[2], y[2], w[2], h[2], "Bitree_3");
}
else {
setfillcolor(YELLOW);
fillroundrect(x[2], y[2], x[2] + w[2], y[2] + h[2], 10, 10);
botton_table(x[2], y[2], w[2], h[2], "Bitree_3");
}
if (msg.x >= x[3] && msg.x <= x[3] + w[3] && msg.y >= y[3] && msg.y <= y[3] + h[3]) {
setfillcolor(RED);
fillroundrect(x[3], y[3], x[3] + w[3], y[3] + h[3], 10, 10);
botton_table(x[3], y[3], w[3], h[3], "Bitree_4");
}
else {
setfillcolor(YELLOW);
fillroundrect(x[3], y[3], x[3] + w[3], y[3] + h[3], 10, 10);
botton_table(x[3], y[3], w[3], h[3], "Bitree_4");
}
if (msg.x >= x[4] && msg.x <= x[4] + w[4] && msg.y >= y[4] && msg.y <= y[4] + h[4]) {
setfillcolor(RED);
fillroundrect(x[4], y[4], x[4] + w[4], y[4] + h[4], 10, 10);
botton_table(x[4], y[4], w[4], h[4], "退出");
}
else {
setfillcolor(YELLOW);
fillroundrect(x[4], y[4], x[4] + w[4], y[4] + h[4], 10, 10);
botton_table(x[4], y[4], w[4], h[4], "退出");
}
}
EndBatchDraw();
}
if (checkt) {
break;
}
}
return 0;
}

總結

第一次寫這個,,,沒啥經驗,單純想發發玩,有什么說錯的地方可以指出來,

總體操作不算繁瑣,600行輕松解決作業 OvO

轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/374855.html

標籤:其他

上一篇:紅黑樹(C++實作)

下一篇:Java崗大廠面試百日沖刺 - 榷訓月累,每日三題【Day51】—— tomcat

標籤雲
其他(157675) Python(38076) JavaScript(25376) Java(17977) C(15215) 區塊鏈(8255) C#(7972) AI(7469) 爪哇(7425) MySQL(7132) html(6777) 基礎類(6313) sql(6102) 熊猫(6058) PHP(5869) 数组(5741) R(5409) Linux(5327) 反应(5209) 腳本語言(PerlPython)(5129) 非技術區(4971) Android(4554) 数据框(4311) css(4259) 节点.js(4032) C語言(3288) json(3245) 列表(3129) 扑(3119) C++語言(3117) 安卓(2998) 打字稿(2995) VBA(2789) Java相關(2746) 疑難問題(2699) 细绳(2522) 單片機工控(2479) iOS(2429) ASP.NET(2402) MongoDB(2323) 麻木的(2285) 正则表达式(2254) 字典(2211) 循环(2198) 迅速(2185) 擅长(2169) 镖(2155) 功能(1967) .NET技术(1958) Web開發(1951) python-3.x(1918) HtmlCss(1915) 弹簧靴(1913) C++(1909) xml(1889) PostgreSQL(1872) .NETCore(1853) 谷歌表格(1846) Unity3D(1843) for循环(1842)

熱門瀏覽
  • 面試突擊第一季,第二季,第三季

    第一季必考 https://www.bilibili.com/video/BV1FE411y79Y?from=search&seid=15921726601957489746 第二季分布式 https://www.bilibili.com/video/BV13f4y127ee/?spm_id_fro ......

    uj5u.com 2020-09-10 05:35:24 more
  • 第三單元作業總結

    1.前言 這應該是本學期最后一次寫作業總結了吧。總體來說,對作業的節奏也差不多掌握了,作業做起來的效率也更高了。雖然和之前的作業一樣,作業中都要用到新的知識,但是相比之前,更加懂得了如何利用工具以及資料。雖然之間卡過殼,但總體而言,這幾次作業還算完成的比較好。 2.作業程序總結 相比前兩個單元,此單 ......

    uj5u.com 2020-09-10 05:35:41 more
  • 北航OO(2020)第四單元博客作業暨課程總結博客

    北航OO(2020)第四單元博客作業暨課程總結博客 本單元作業的架構設計 在本單元中,由于UML圖具有比較清晰的樹形結構,因此我對其中需要進行查詢操作的元素進行了包裝,在樹的父節點中存盤所有孩子的參考。考慮到性能問題,我采用了快取機制,一次查詢后盡可能快取已經遍歷過的資訊,以減少遍歷次數。 本單元我 ......

    uj5u.com 2020-09-10 05:35:48 more
  • BUAA_OO_第四單元

    一、UML決議器設計 ? 先看下題目:第四單元實作一個基于JDK 8帶有效性檢查的UML(Unified Modeling Language)類圖,順序圖,狀態圖分析器 MyUmlInteraction,實際上我們要建立一個有向圖模型,UML中的物件(元素)可能與同級元素連接,也可與低級元素相連形成 ......

    uj5u.com 2020-09-10 05:35:54 more
  • 6.1邏輯運算子

    邏輯運算子 1. && 短路與 運算式1 && 運算式2 01.運算式1為true并且運算式2也為true 整體回傳為true 02.運算式1為false,將不會執行運算式2 整體回傳為false 03.只要有一個運算式為false 整體回傳為false 2. || 短路或 運算式1 || 運算式2 ......

    uj5u.com 2020-09-10 05:35:56 more
  • BUAAOO 第四單元 & 課程總結

    1. 第四單元:StarUml檔案決議 本單元采用了圖模型決議UML。 UML檔案可以抽象為圖、子圖、邊的邏輯結構。 在實作中,圖的節點包括類、介面、屬性,子圖包括狀態圖、順序圖等。 采用了三次遍歷UML元素的方法建圖,第一遍遍歷建點,第二、三次遍歷設定屬性、連邊,實作圖物件的初始化。這里借鑒了一些 ......

    uj5u.com 2020-09-10 05:36:06 more
  • 談談我對C# 多型的理解

    面向物件三要素:封裝、繼承、多型。 封裝和繼承,這兩個比較好理解,但要理解多型的話,可就稍微有點難度了。今天,我們就來講講多型的理解。 我們應該經常會看到面試題目:請談談對多型的理解。 其實呢,多型非常簡單,就一句話:呼叫同一種方法產生了不同的結果。 具體實作方式有三種。 一、多載 多載很簡單。 p ......

    uj5u.com 2020-09-10 05:36:09 more
  • Python 資料驅動工具:DDT

    背景 python 的unittest 沒有自帶資料驅動功能。 所以如果使用unittest,同時又想使用資料驅動,那么就可以使用DDT來完成。 DDT是 “Data-Driven Tests”的縮寫。 資料:http://ddt.readthedocs.io/en/latest/ 使用方法 dd. ......

    uj5u.com 2020-09-10 05:36:13 more
  • Python里面的xlrd模塊詳解

    那我就一下面積個問題對xlrd模塊進行學習一下: 1.什么是xlrd模塊? 2.為什么使用xlrd模塊? 3.怎樣使用xlrd模塊? 1.什么是xlrd模塊? ?python操作excel主要用到xlrd和xlwt這兩個庫,即xlrd是讀excel,xlwt是寫excel的庫。 今天就先來說一下xl ......

    uj5u.com 2020-09-10 05:36:28 more
  • 當我們創建HashMap時,底層到底做了什么?

    jdk1.7中的底層實作程序(底層基于陣列+鏈表) 在我們new HashMap()時,底層創建了默認長度為16的一維陣列Entry[ ] table。當我們呼叫map.put(key1,value1)方法向HashMap里添加資料的時候: 首先,呼叫key1所在類的hashCode()計算key1 ......

    uj5u.com 2020-09-10 05:36:38 more
最新发布
  • 【中介者設計模式詳解】C/Java/JS/Go/Python/TS不同語言實作

    * 中介者模式是一種行為型設計模式,它可以用來減少類之間的直接依賴關系,
    * 將物件之間的通信封裝到一個中介者物件中,從而使得各個物件之間的關系更加松散。
    * 在中介者模式中,物件之間不再直接相互互動,而是通過中介者來中轉訊息。 ......

    uj5u.com 2023-04-20 08:20:47 more
  • 露天煤礦現場調研和交流案例分享

    他們集團的資訊化公司及研究院在一個礦區正在做智能礦山的統一平臺的 試點,專案投資大概1億,包括了礦山的各方面的內容,顯示得我們這次交流有點多余。他們2年前開始做智能礦山的規劃,有很多煤礦行業專家的加持,他們的描述是非常完美,但是去年底應該上線的平臺,現在還沒有看到影子。他們確實有很多場景需求,但是被... ......

    uj5u.com 2023-04-20 08:20:25 more
  • 《社區人員管理》實戰案例設計&個人案例分享

    設計是一個讓人夢想成真程序,開始編碼、測驗、除錯之前進行需求分析和架構設計,才能保證關鍵方面都做正確 ......

    uj5u.com 2023-04-20 08:20:17 more
  • 軟體架構生態化-多角色交付的探索實踐

    作為一個技術架構師,不僅僅要緊跟行業技術趨勢,還要結合研發團隊現狀及痛點,探索新的交付方案。在日常中,你是否遇到如下問題 “ 業務需求排期長研發是瓶頸;非研發角色感受不到研發技改提效的變化;引入ISV 團隊又擔心質量和安全,培訓周期長“等等,基于此我們探索了一種新的技術體系及交付方案來解決如上問題。 ......

    uj5u.com 2023-04-20 08:20:10 more
  • 【中介者設計模式詳解】C/Java/JS/Go/Python/TS不同語言實作

    * 中介者模式是一種行為型設計模式,它可以用來減少類之間的直接依賴關系,
    * 將物件之間的通信封裝到一個中介者物件中,從而使得各個物件之間的關系更加松散。
    * 在中介者模式中,物件之間不再直接相互互動,而是通過中介者來中轉訊息。 ......

    uj5u.com 2023-04-20 08:19:44 more
  • 露天煤礦現場調研和交流案例分享

    他們集團的資訊化公司及研究院在一個礦區正在做智能礦山的統一平臺的 試點,專案投資大概1億,包括了礦山的各方面的內容,顯示得我們這次交流有點多余。他們2年前開始做智能礦山的規劃,有很多煤礦行業專家的加持,他們的描述是非常完美,但是去年底應該上線的平臺,現在還沒有看到影子。他們確實有很多場景需求,但是被... ......

    uj5u.com 2023-04-20 08:19:07 more
  • 《社區人員管理》實戰案例設計&個人案例分享

    設計是一個讓人夢想成真程序,開始編碼、測驗、除錯之前進行需求分析和架構設計,才能保證關鍵方面都做正確 ......

    uj5u.com 2023-04-20 08:18:57 more
  • 軟體架構生態化-多角色交付的探索實踐

    作為一個技術架構師,不僅僅要緊跟行業技術趨勢,還要結合研發團隊現狀及痛點,探索新的交付方案。在日常中,你是否遇到如下問題 “ 業務需求排期長研發是瓶頸;非研發角色感受不到研發技改提效的變化;引入ISV 團隊又擔心質量和安全,培訓周期長“等等,基于此我們探索了一種新的技術體系及交付方案來解決如上問題。 ......

    uj5u.com 2023-04-20 08:18:49 more
  • 05單件模式

    #經典的單件模式 public class Singleton { private static Singleton uniqueInstance; //一個靜態變數持有Singleton類的唯一實體。 // 其他有用的實體變數寫在這里 //構造器宣告為私有,只有Singleton可以實體化這個類! ......

    uj5u.com 2023-04-19 08:42:51 more
  • 【架構與設計】常見微服務分層架構的區別和落地實踐

    軟體工程的方方面面都遵循一個最基本的道理:沒有銀彈,架構分層模型更是如此,每一種都有各自優缺點,所以請根據不同的業務場景,并遵循簡單、可演進這兩個重要的架構原則選擇合適的架構分層模型即可。 ......

    uj5u.com 2023-04-19 08:42:41 more