Time of Update: 2018-12-04
#include <stdio.h>#include <stdlib.h>#include <malloc.h>#define MAX_HEIGHT 10#define LEAF -1typedef struct BTreenode{ BTreenode* lchild; BTreenode* rchild; int value; }BTreenode,*Btree;BTreenode*
Time of Update: 2018-12-04
文章目錄 二叉排序數相關總結: 二叉排序數相關總結:二叉排序樹屬於動態尋找表,是一棵完全二叉樹。它的性質為:或者是一個空樹,或者滿足: 1.如果左子樹不空,那麼左子樹所有節點的值都小於根節點的值。 2.如果右子樹不空,那麼右子樹所有節點的值都大於根節點的值。 3.它的左右子樹也分別是一個二叉尋找樹。可以看出,二叉尋找樹是一個遞迴的定義(樹本身就是遞迴的定義。)如示,就是一個簡單的二叉尋找樹:
Time of Update: 2018-12-04
#include <stdio.h>#include <malloc.h>typedef struct BTreeNode{int value;BTreeNode * lchild;BTreeNode * rchild;}BTreeNode;void visit(BTreeNode * node){printf("%d ",node->value);}void preOrder(BTreeNode *
Time of Update: 2018-12-04
本文系轉載。原文地址:http://blog.csdn.net/zhuimengzh/article/details/6806553@zhuimengzh#include "stdafx.h"#include <iostream>using namespace std;//用棧類比隊列class Data{public:Data():data(0),next(NULL){}Data(int i):data(i),next(NULL){}int data;Data
Time of Update: 2018-12-04
#include <stdio.h>#include <stdlib.h>bool isSequence(int *array, int start,int end) { if(start > end ){ return false; } if(start == end){ return true; } int root = array[end-1]; int i = start; while(
Time of Update: 2018-12-04
隊列的鏈式實現源碼如下:這是之後的鏈隊列操作的基礎。#include <stdio.h>#include <stdlib.h>#include <malloc.h>#define OK 1#define ERROR 0#define QOVERFLOW -1 typedef int QElem,Status;typedef struct QNode{ QElem data; QNode *next;
Time of Update: 2018-12-04
#include <stdio.h>#include <stdlib.h>#include <malloc.h>#include <math.h>//棧的初始最大容量 #define STACK_MAX_SIZE 100//棧的容量增量 #define INCREAMENT 10//狀態函數 #define ERROR 0#define OK 1#define SOVERFLOW -1 #define YES 1#define NO 0
Time of Update: 2018-12-04
題目描述:對於一個非空棧,請設計一個演算法顛倒棧中的元素。首先我們設計的棧的實現代碼是:/* * 問題描述:棧實現的基本代碼。 * @author : xiaoq-ohmygirl * @time : 2012-07-03 **/ #include <stdio.h>#include <stdlib.h>#include <malloc.h>#include <math.h>//棧的初始最大容量 #define STACK_MAX_SIZE
Time of Update: 2018-12-04
#include <stdio.h>#include <stdlib.h>#include <malloc.h>#define LEAF -1typedef struct BTreeNode{ BTreeNode* lchild; BTreeNode* rchild; int value; }BTreenode,*Btree;BTreenode* createTree(){ BTreeNode* T;
Time of Update: 2018-12-04
/* * 演算法功能:建立單鏈表,交換單鏈表中的兩個元素。 * 演算法中的單鏈表是帶頭結點的。 * 函數說明:nop * @author:xiaoq-ohmygirl * @time :2012-06-20 **/#include <stdio.h>#include <malloc.h>#include <stdlib.h>#define MAXNODE 10typedef struct node{ int data; node* next;}*
Time of Update: 2018-12-04
#include <stdio.h>#include <stdlib.h>#include <malloc.h>#define LEAF -1typedef struct BTreeNode{ BTreeNode* lchild; BTreeNode* rchild; int value; }BTreenode,*Btree;BTreenode* createTree(){ BTreeNode* T;
Time of Update: 2018-12-04
題目描述:定義棧的資料結構,要求添加一個min函數,能夠得到棧的最小元素。要求函數min,push,pop的時間複雜度都是O(1).解法1:另外設計一個最小棧做輔助結構,記錄棧中的最小元素。元素棧中儲存要入棧的元素。最小棧儲存當前的最小元素。那麼: 1.入棧時,先入元素棧,同時與最小棧頂元素比較,如果比棧頂元素小,則最小元素入最小棧,否則,棧頂元素入最小棧。
Time of Update: 2018-12-04
/* * 演算法功能:建立單鏈表,判斷單鏈表是否有環。 * 函數說明: * 1.initLinkList():建立無環無頭結點單鏈表。 * 2.initLoopList():建立有環的鏈表。 * 3.isLoopLink():判斷鏈表是否有環。 * @author:xiaoq-ohmygirl * @time :2012-06-25 **/#include <stdio.h>#include <malloc.h>#include
Time of Update: 2018-12-04
/* *1.編程之美上的解法。 */struct NODE{ NODE* pLeft; // 左子樹 NODE* pRight; // 右子樹 int nMaxLeft; // 左子樹中的最長距離 int nMaxRight; // 右子樹中的最長距離 char chValue; // 該節點的值};int nMaxLen = 0;// 尋找樹中最長的兩段距離void FindMaxLen(NODE*
Time of Update: 2018-12-04
#include <stdio.h>#include <string.h>#include <stdlib.h>#include <queue>#include <stack> #include <iostream> #include <malloc.h>#define LEAF -1using namespace std;typedef struct BTreeNode{ BTreeNode*
Time of Update: 2018-12-04
#include <stdio.h>#include <stdlib.h>//將編號為n的盤子移動從x移動到y void move(char x,int n,char y){ printf("%d號盤子 :%c -> %c\n",n,x,y); } void hanoi(int n,char x,char y,char z){ if(n == 1){ move(x,1,z); } else{
Time of Update: 2018-12-04
#include <stdio.h>#include <string.h>#include <stdlib.h>#include <queue>#include <iostream> #include <malloc.h>#define LEAF -1using namespace std; typedef struct BTreeNode{ BTreeNode* lchild; BTreeNode*
Time of Update: 2018-12-04
/**括弧匹配問題描述:對於嵌套的括弧形式,用棧檢測是否是合法的形式。例如【()】()()就是合法的,(【()()】)也是合法的,((【)】())等是不合法的。*/#include <stdio.h>#include <stdlib.h>#include <malloc.h>#include <assert.h>//棧的初始最大容量 #define STACK_MAX_SIZE 100//棧的容量增量 #define INCREAMENT 10//
Time of Update: 2018-12-04
#include <stdio.h>#include <stdlib.h>#include <malloc.h>#define LEAF -1typedef struct BTreenode{ BTreenode* lchild; BTreenode* rchild; int value; }BTreenode,*Btree;BTreenode* createTree(){ BTreenode* T;
Time of Update: 2018-12-04
/*數值轉換問題描述:對於十進位數值,轉換為其他的2進位或者8進位數值問題,可以用棧來解決。 *具體原理:N= (N div d) * d + N mod d; **///演算法conversion實現從十進位轉換為二進位或者八進位並輸出。#include <stdio.h>#include <stdlib.h>#include <malloc.h>#include <assert.h>//棧的初始最大容量 #define