- 博客(46)
- 资源 (3)
- 收藏
- 关注
原创 折半查找的递归与非递归方法实现
#include using namespace std; //折半查找的递归方法实现int BSearch(int *arr,int key,int low,int high){ if(low>high) return -1; int mid=(low+high)/2; if(key==arr[mid]) return mid; else if(k
2013-12-13 10:20:56 1460
原创 二叉树的C++实现
/*--------BTree.h---------*/#ifndef _BTREE_H_#define _BTREE_H_ #include using namespace std; //树节点的结构typedef class bTree{public: int data; bTree *lchild,*rchild;}bTreeNode,*p
2013-12-12 18:04:28 656
原创 物体的阻尼运动
#include #include const int X=200,Y=50; //程序窗口左上角相对于屏幕的坐标 const int WIDTH=640,HEIGHT=480; // //程序窗口的宽与高DWORD tPre,tNow; //tPre记录上一次绘图的时间,tNow记录此次准备绘图的时间int x=0,y=0,vx=3,vy=0,gy=1;
2013-12-12 17:15:34 1219
原创 队列的链表实现
#include #include using namespace std;typedef class List{public: int data; class List* next;}Node,*Link; Link front=NULL;Link rear=NULL; //队列数据的存入void Add_Queue(int value)
2013-12-11 11:28:00 529
原创 队列的数组实现
#include #include using namespace std; #define MAXSIZE 10int queue[MAXSIZE];int front=-1;int rear=-1; bool IsEmpty(){ if(front==rear) return true; return false;} bool
2013-12-11 11:26:43 561
原创 堆栈的链表实现
#include #include using namespace std; typedef class List{public: int data; class List* next;}Node,*Link; //指向堆栈顶端的指针Link top=NULL; //判断是否为空堆栈bool IsEmpty(){ if(NULL=
2013-12-11 10:01:20 591
原创 堆栈的数组实现
#include #include using namespace std; #define MAXSIZE 20int top=-1;int Stack[MAXSIZE]; //判断是否为空堆栈bool IsEmpty(){ if(-1==top) return true; return false;} //将指定的数据存入堆栈
2013-12-11 09:37:36 548
原创 物体的加速运动(只受重力影响)
#include #include const int X=200,Y=50; //程序窗口左上角相对于屏幕的坐标 const int WIDTH=640,HEIGHT=480; // //程序窗口的宽与高DWORD tPre,tNow; //tPre记录上一次绘图的时间,tNow记录此次准备绘图的时间int x=0,y=0,vx=3,vy=0,gy=
2013-12-10 20:15:32 776
原创 N*N矩阵
#include #include using namespace std; int main(){ int N,s,i,j,squa; cout cin>>N; int **a=new int*[N]; if(NULL==a) return 0; for(i=0;i a[i]=new int[N]; squa=N*N;
2013-12-10 15:50:20 1424
原创 螺旋队列
#include #include using namespace std;#define max(a,b) ((a)>(b)?(a):(b))#define abs(a) ((a)>0?(a):(-a)) int foo(int x,int y){ int t=max(abs(x),abs(y)); int u=t+t; int v=u-1; v=
2013-12-10 15:46:38 469
原创 数字斜塔
#include #include using namespace std; int main(){ int arr[40][40]; int i,j,num; arr[0][0]=1; cout cin>>num; for(i=0;i { if(i>0) arr[i][0]=arr[i-1][0]+i; for(j=0
2013-12-10 15:41:19 800
原创 单链表的非空判断及长度的输出
#include using namespace std;typedef class List{public: int num; char name[10]; class List* next;}Node,*Link; //创建链表Link Create_List(Link pHead){ int n; cout cin>>n;
2013-12-10 13:54:38 952
原创 多个单链表的链接
#include using namespace std;typedef class List{public: int num; char name[10]; class List* next;}Node,*Link; //创建链表Link Create_List(Link pHead){ int n; cout cin>>n;
2013-12-10 13:49:12 680
原创 单链表反转
#include using namespace std;typedef class List{public: int num; char name[10]; class List* next;}Node,*Link; //创建链表Link Create_List(Link pHead){ int n; cout cin>>n; //
2013-12-10 13:43:28 454
原创 单链表结点删除
#include using namespace std;typedef class List{public: int num; char name[10]; class List* next;}Node,*Link; //创建链表Link Create_List(Link pHead){ int n; cout cin>>n; //
2013-12-10 13:36:38 969
原创 单链表结点插入
#include using namespace std;typedef class List{public: int num; char name[10]; class List* next;}Node,*Link; //创建链表Link Create_List(Link pHead){ int n; cout cin>>n; //
2013-12-10 13:29:08 938
原创 单链表结点查找
#include using namespace std;typedef class List{public: int num; char name[10]; class List* next;}Node,*Link; //创建链表Link Create_List(Link pHead){ int n; cout cin>>n; //
2013-12-10 13:23:43 780
原创 单链表的创建,遍历输出及释放
#include using namespace std; typedef class List{public: int num; char name[10]; class List* next;}Node,*Link; //创建链表Link Create_List(Link pHead){ int n; cout cin>>n;
2013-12-10 13:17:44 1574
原创 物体匀速运动的实现
#include #include const int X=200,Y=50; //程序窗口左上角相对于屏幕的坐标 const int WIDTH=640,HEIGHT=480; // //程序窗口的宽与高 DWORD tPre,tNow; //tPre记录上一次绘图的时间,tNow记录此次准备绘图的时间int x=50,y=50,vx=10,vy
2013-12-09 23:29:14 1550
原创 下三角形数组转换为一维数组
(1) 将大小为n*n的下三角数组转换成以行为主的一维数组,且不存储内容为0的元素!data[i][j]的位置 =i*(i+1)/2+j; (2) 将大小为n*n的下三角数组转换成以列为主的一维数组,且不存储内容为0的元素!data[i][j]的位置=[n+(n-j+1)]*j/2+(i-j) (1)
2013-12-09 12:04:43 2482
原创 上三角形数组转换为一维数组
(1)将大小为n*n的上三角数组转换成以行为主的一维数组,且不存储内容为0的元素!data[i][j]的位置=[n+(n-i+1)]*i/2+(j-i) (2)将大小为n*n的上三角数组转换成以列为主的一维数组,且不存储内容为0的元素!data[i][j]的位置=j*(j+1)/2+i (1) #include #include using namesp
2013-12-09 11:44:28 3763 1
原创 稀疏数组
二维数组:求某一元素在数组中的位置。1、以行为主: data[i][j]的内存位置=第一个元素的位置+[ (i * 每一行元素个数)+j ] * ( 数据类型所占空间大小) 2、以列为主: data[i][j]的内存位置=第一个元素的位置+[ (j * 每一行元素个数)+i ] * ( 数据类型所占空间大小)
2013-12-09 10:43:25 554
原创 实现把一个字符串的后steps位移动到字符串前面
#include using namespace std; void LoopMove ( char *pStr, int steps ) { int n = strlen( pStr ) - steps; char tmp[10]; //假设steps为2 //把pStr+n即从'h'位置起steps长度的内容即”hi"复制到tmp中 memcpy( tm
2013-12-09 09:41:28 759
原创 行为型AI:寻找迷宫出口
#include #include using namespace std; const int X=200,Y=100; //程序窗口左上角相对于屏幕的坐标 const int WIDTH=420,HEIGHT=440; //程序窗口的宽与高const int rows=8,cols=8;
2013-12-08 23:16:53 959
原创 老鼠走迷宫 (栈实现)
#include <iostream>using namespace std;//定义四个方向#define EAST MAZE[x][y+1]#define WEST MAZE[x][y-1]#define SOUTH MAZE[x+1][y]#define NORTH MAZE[x-1][y]//起点(1,1),终点(8,10)const in...
2013-12-08 19:06:13 2498 1
原创 老鼠走迷官(二)
由于迷宫的设计,老鼠走迷宫的入口至出口路径可能不只一条,如何求出所有的路径。只要在老鼠走至出口时显示经过的路径,然后退 回上一格重新选择下一个位置继续递回就可以了! #include using namespace std;int maze[9][9] = { {2, 2, 2, 2, 2, 2, 2, 2, 2}, {2, 0, 0, 0, 0, 0, 0, 0, 2
2013-12-08 12:59:43 697
原创 老鼠走迷官(一)
老鼠的走法有上、左、下、右四个方向,在每前进一格之后就选一个方向前进,无法前 进时退回选择下一个可前进方向,如此在阵列中依序测试四个方向,直到走到出口为止。 #include using namespace std;int visit(int,int);int maze[7][7] = { {2, 2, 2, 2, 2, 2, 2}, {2, 0, 0, 0,
2013-12-08 12:54:57 672
原创 删除数组中重复出现的元素,只留下一个,排序后输出
#include #include using namespace std;//快速排序void quick_sort(int *unsorted,int low,int high){ if(low { int i=low,j=high,tmp=unsorted[low]; while(i { while(i=tmp) j--;
2013-12-07 22:51:26 1737
原创 巴斯卡三角形, 即杨辉三角
#include #include using namespace std;int main(){ int N,i,j; cout cin>>N; int **a=new int*[N]; for(i=0;i a[i]=new int[N]; cout for(i=0;i { a[i][0]=a[i][i]=1; //输入每一行数前
2013-12-07 14:49:26 874
原创 透明窗口
#include #include const int X=200;const int Y=50;const int WIDTH=800;const int HEIGHT=600;const std::string szClassTitle="透明窗口"; LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);int
2013-12-07 12:10:44 644
原创 三色旗问题
//红白蓝三种颜色分别用0,1,2表示。//开始时0,1,2是乱序。//排列后0在前,1在中,2在后。 #include using namespace std;const int N=10;void swap(int &a,int &b){ if(a!=b) { a^=b; b^=a; a^=b; }} void shuf
2013-12-07 10:53:59 658
原创 将一个数转换成n进制(2<=n<=26)
#include #include #include using namespace std;char invert(int n){ for(int i=0;i { if(n==i) return (i+'0'); }} int main(){ int num,n; string str=""; cout cin>>nu
2013-12-07 10:35:21 769
原创 字符串语句逆向输出
#include int main(){ char str[30]; gets(str); for(int i=strlen(str)-1,j=0;i>j;i--,j++) { char tmp=str[i]; str[i]=str[j]; str[j]=tmp; } puts(str); return 0;}
2013-12-06 23:06:26 613
原创 将一个正整数逆向输出
#include int main(){ int n,d; std::cin>>n; do{ d=n%10; std::cout n/=10; }while(n!=0); std::cout}
2013-12-06 22:06:26 1604
原创 求1-2+3- …… +n 的值!
#include using namespace std;long fn(long n){ while(n { cout cout cin>>n; } if(n%2==0) return (-1)*(n/2); else return (-1)*(n/2)+n;} int main(){ int n; cout
2013-12-06 22:01:27 998
原创 求最大公约数与最小公倍数
#include using namespace std;/*递归法求最大公约数int gcd(int m,int n){ if(n==0) return m; else return gcd(n,m%n);}*/int gcd(int x,int y){ while(x!=y) { if(x>y) x-=y; e
2013-12-06 21:48:56 555
原创 用递归法将一个字符串逆向输出
#include using namespace std;char str[30];int len=0;void reverse(int n){ if(n { reverse(n+1); cout }} int main(){ cin>>str; len=strlen(str); cout cout reverse(0
2013-12-06 20:52:07 1070
原创 删去字符串中包含的a、e、i、o、u字符
#include using namespace std;char *removeStr(char *p){ char *head=new char,*q=NULL; q=head; while(NULL!=p && '\0'!=*p) { if('a'==*p || 'e'==*p || 'i'==*p || 'o'==*p || 'u'==*p) p+
2013-12-06 20:45:39 1027
原创 归并排序法
#include using namespace std;//合并数组void MergeArray(int *unsorted,int *sorted,int first,int mid,int last){ int i=first,j=mid+1,k=0; while(i { if(unsorted[i] sorted[k++]=unsorted[i+
2013-12-06 20:28:54 481
原创 堆排序法
#include using namespace std;void swap(int &a,int &b){ if(a!=b) { a^=b; b^=a; a^=b; }} void HeapAdjust(int *unsorted,int parent,int len){ int tmp=unsorted[parent]; int
2013-12-06 20:14:00 506
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人