约瑟夫问题单向循环链表解决简版

#include<stdio.h> #include<stdlib.h> #define N 13 //总人数 typedef struct Node { int Data; struct Node *Next; }List,*Position; Position Create(void); Position Delete(Position Head,Position P); Position Deal(Position Head); void Traverse(Position Head); int main() //测试 { P...
2017-05-27 23:12 | 阅读 1731 次 | 评论 0 条

C++实现的红黑树基本操作(English notes very cool!!)

#include<iostream> #include<cstdlib> using namespace std; #define RED 1 #define BLACK 0 typedef struct TreeNode { int Element; int Color; TreeNode *Parent; TreeNode *Left; TreeNode *Right; TreeNode() { Color=BLACK; //let initial node become black } }*MyRBTree; MyRBTree ...
2017-05-09 21:41 | 阅读 1735 次 | 评论 1 条

递归实现的AVLtree的基本操作(嘿嘿,英文注释蛮爽的)

#include<iostream> #include<cstdlib> using namespace std; typedef struct TreeNode { int Element; int Height; TreeNode *Left; TreeNode *Right; }*MyAVLTree; MyAVLTree MakeEmpty(MyAVLTree &amp;T); void InorderTraverse(const MyAVLTree &amp;T); static int Max(int a,int b); static int ...
2017-04-30 20:23 | 阅读 1438 次 | 评论 0 条

递归法实现二叉查找树的基本操作

#include<iostream> #include<cstdlib> using namespace std; /*查找二叉树,这里用的都是无敌的递归方法,因为它极容易理解, 也很容易编程,但值得注意的是返回值很重要*/ typedef struct TreeNode { int Element; TreeNode *Left; TreeNode *Right; }TreeNode,*MyTree; MyTree MakeEmpty(MyTree &amp;T); //二叉树置空 void InorderTraverse(const MyTree ...
2017-04-29 22:36 | 阅读 1646 次 | 评论 0 条

全局有效的数据结构

一开始我用的变量是局部的它的毛病就是所有的操作只能做一次,然后啥也没改变。 那么解决的一个方法就是 引用地址 引用地址使得全局有效 不说了 直接上上点代码 typedef struct TreeNode { char Element; TreeNode *Left; TreeNode *Right; }*MyTree; void Exchange(MyTree T) { if(T) { MyTree Temp=NULL; if(T->Left||T->Right) { ...
2017-04-28 16:22 | 阅读 1254 次 | 评论 0 条

数组实现的Circle队列

#include<iostream> #include<cstdlib> #define MAX 100 using namespace std; typedef struct Queue { int Array[MAX]; int Front; int Rear; } *CircleQueue; CircleQueue Create(void); //创建一个队列 int IsEmpty(CircleQueue Q); //是否为空 int IsFull(CircleQueue Q); //是否已满 void EnQueue(Circle...
2017-04-27 19:19 | 阅读 1015 次 | 评论 0 条

数组实现的MyQueue顺序队列

#include<iostream> #include<cstdlib> using namespace std; typedef struct Queue { int *Array; int Front,Rear; }*MyQueue; MyQueue Create(void); //创建一个队列 int IsEmpty(MyQueue Q); //检验是否为空栈 void DeQueue(MyQueue Q); //出队 void EnQueue(int X,MyQueue Q); //入队 void GetQueueFront(MyQ...
2017-04-24 18:49 | 阅读 1132 次 | 评论 0 条

链表实现的MyQueue顺序队列

#include<iostream> #include<cstdlib> #define MAXSIZE 100 using namespace std; typedef struct Node { struct Node *Next; //队列元素的节点连接 int Element; }MyNode; typedef struct Queue { Node *Front; //Front和Rear连接着各自应有的节点 Node *Rear; int Items; //队列元素的个数,用于判断是否空队列,...
2017-04-23 09:44 | 阅读 1100 次 | 评论 0 条

C/C++栈的链表实现

#include<iostream> #include<cstdlib> #define LEN sizeof(struct Node) using namespace std; struct Node; typedef struct Node *PtrToNode; typedef PtrToNode Position; struct Node //节点 { int Element ; struct Node *Next; }; int IsEmpty(Position Top); //检验空栈 void GetStackTo...
2017-04-22 11:03 | 阅读 1324 次 | 评论 1 条

C/C++栈的数组实现

#include<iostream> #include<cstdlib> using namespace std; int *Array=NULL; int Count=0; void Initial(int Size); //初始化栈 void Push(int Element); //入栈 int GetStackLenth(void);//获取栈的个数 void GetTopOfStack(void);//栈顶元素 void Pop(void); //出栈 void Traverse(void); //遍历 voi...
2017-04-22 10:54 | 阅读 1042 次 | 评论 0 条

DoubleWayList 双向循环链表

//我发现,插入操作时,总是先把New与已有节点连接 #include<iostream> #include<cstdlib> #define LEN sizeof(struct Node) using namespace std; typedef struct Node *PtrToNode; typedef PtrToNode Position; struct Node { int Element; struct Node *Last; struct Node *Next; }; Position Create(void); ...
2017-04-20 20:26 | 阅读 1238 次 | 评论 0 条

SingleCycleList单向循环链表

#include<iostream> #include<cstdlib> using namespace std; #define LEN sizeof(struct Node) #define N 6 typedef struct Node *PtrToNode; typedef PtrToNode Position; struct Node { int Element; struct Node *Next; }; Position Create(void); //创建一个循环链表 void Taverse(Position Hea...
2017-04-17 12:55 | 阅读 1329 次 | 评论 0 条

模拟drunkard的随机漫步

#include<iostream> #include<cmath> #include<cstdlib> using namespace std; const int SHIP=1; const int BAR=2; const int WATER=3; int drunkard(void) { int x=-10; //酒者一开始在酒馆 int y=0; //酒者一开始在跳板中央 int step=0; //初始化酒者的步数 while(abs(x)<=10&amp;&amp;abs(y)<=2) { switch(rand()%...
2017-04-08 14:27 | 阅读 1006 次 | 评论 0 条

函数重载

#include<iostream> using namespace std; //名字相同,但是参数列表不能相同 //跟缺省值一起结合用,可能会出现报错/冲突 //返回值不能作为函数重载的条件 void fun(int a,double b) { cout <<"1: "<<a <<' ' <<b <<endl; } void fun(int a,float b) { cout <<"2: "<<a <<' ' <<b <<endl; } void fun(int a,char c=...
2017-04-04 15:46 | 阅读 846 次 | 评论 0 条

函数缺省值与相对C语言增强版的for循环语句

#include<iostream> using namespace std; void fun(int a,char c,float d=1.233) //带缺省值的函数,从右到左,必须要连续赋予缺省值 { cout <<a <<' ' <<c <<' ' <<d <<endl; for(int i=0;i<10;i++) //可在循环内声明初始变量 { cout <<i <<' ' ; } //cout <<i; //这样是不对的,因为上面for循环里面的i只作用于循环内而非整个函数 cout <<endl...
2017-04-04 14:26 | 阅读 1096 次 | 评论 0 条

引用的一个小应用

#include<iostream> using namespace std; void Swap(int &amp;Num1,int &amp;Num2) //引用做参数 { int Temp=Num1; Num1=Num2; Num2=Temp; cout <<Num1 <<' ' <<Num2 <<endl; } void Swap1(int a,int b) //普通参数, { int Temp=a; a=b; b=Temp; cout <<a <<' ' <<b <<endl; } void ...
2017-04-04 13:29 | 阅读 830 次 | 评论 0 条

命名空间

namespace name //不能重复 { void sort() { }; } using namespace name; //类似于头文件之类的吧,不过放在代码之中,必须放在namespace name之后 int main() { std::sort(); }
2017-03-29 12:51 | 阅读 716 次 | 评论 0 条

我的第一个c++program

#include<iostream> int main() { using namespace std; cout << "let's coding !haha~" <<endl;//输出语句且换行 cout ; //这个语句可以跳过 cout << "you wont's be so worried!"; return 0; }
2017-03-28 20:22 | 阅读 841 次 | 评论 0 条