摘要:#include<iostream.h>void fun(int m)//m的m次方,允许重复的全排列{ int *a=new int[m+1]; for(int i=0;i<=m;i++) a[i]=0; while(a[m]!=1) { for(int i=0;i<m;i++) cout<<a[i]<<" "; cout<<endl; for(int j=0;j<=m;j++) { a[j]+=1; if(a[j]>=m) a[j...
阅读全文
摘要:#include <iostream.h>#include <MATH.H>int fun(int N){ int num=0; int length=(int)log10(N)+1; for (int i=1;i<=length;i++) { num+=N/(int)pow(10,i)*(int)pow(10,i-1); int index=N/(int)pow(10,i-1)%10; switch(index) { case 0: ...
阅读全文
摘要:#include <iostream.h>#include <stdlib.h>#include <string.h>#include <time.h>#include <math.h>#include <stdio.h>typedef struct Point { int x; int y;}Point;/*typedef struct Stack{ Point Array[100]; int length;}Stack;*/void fun(int (*a)[10],int i,int j,int m,int&
阅读全文
摘要:#include <iostream.h>#include <stdlib.h>#include <string.h>#include <time.h>#include <math.h>void fun(int (*a)[5],int i,int j,int m){ if(i<0||j<0||i>=m||j>=m||a[i][j]!=1) return; a[i][j]=2; fun(a,i-1,j,m); fun(a,i+1,j,m); fun(a,i,j-1,m); fun(a,i,j+1,m);}type
阅读全文
摘要:#include <iostream.h>#include <string.h>#include <stdlib.h>#include <math.h>void fun(const char *a,const char *b ,char *c){ int remainder=0; int length=strlen(a)>strlen(b)?strlen(a):strlen(b); int x=length; for (int i=strlen(a)-1,j=strlen(b)-1;i>=0||j>=0;i--,j--) { i
阅读全文
摘要:1000的阶乘 2568位#include <iostream.h>#include <string.h>#include <stdlib.h>#include <math.h>void fun(const char *a,const char *b ,char *c){ int index; if (a[0]>'0'&&b[0]>'0')//两个正数相加 { index=0; } if (a[0]=='-'&&b[0]=='-')//两个
阅读全文
摘要:#include <iostream.h>#include <string.h>void fun(char *a,char *b,char *c){ if (strlen(b)==0) { strcpy(c,a); return; } char *current=strstr(a,b); char *head=a; while (current!=NULL) { strncat(c,head,current-head); head=current+strlen(b); current...
阅读全文
摘要://堆排序#include <iostream.h>void main(){ int a[12]={2,4,6,34,31,24,65,37,87,68,90,23}; int b[12]; for (int i=0;i<12;i++) { b[i]=a[i]; int temp=i; while (temp-1>=0) { if (b[(temp-1)/2]<b[temp]) { int x=b[(temp-1)/2]; ...
阅读全文
摘要://基数排序#include<iostream.h>void funCount(int *count,int* a,int length,int num)//对应位上数字的个数{ for (int i=0;i<length;i++) { int x=a[i]; for (int j=2;j<=num;j++) { x=x/10; } x=x%10; count[x]++; }}void funIndex(int* count,int* index)//对应位上数字开始存放...
阅读全文
摘要:#include<iostream.h>int findValue(int k,int* a,int start,int end){ int low=start; int high=end; int x=a[start]; int flag=0; while (low!=high) { if (flag==0) { for (int j=high;j>=low;j--) { if (a[j]<x) { ...
阅读全文
摘要://快速排序算法#include<iostream.h>void sort(int start,int end,int *a){ if (start>=end) return; int low=start; int high=end; int x=a[start]; int flag=0; while (low!=high) { if (flag==0)//左边空,从右向左找比x小的值 { for(int j=high;j>=low;j--) { ...
阅读全文
摘要://顺序查找:技巧,卫兵法,在查找的线性表后加入要查找的元素while(a[i]!=x) i++;return i;//折半查找:low height mid O(log n);//索引分块:把值的范围分成若干个区域,每个区域对应着起始的下标//二叉排序树:动态查找,找不到插入该节点,特点,插入的点时叶子p=tree;parent=NULL;while(p){ if(p->element=key) break; if(p->element>key) parent=p;p=p->pLchild; if(p->element<key) parent=p;p=p-
阅读全文
摘要:typedef struct DataType {}DataType;typedef struct Node { DataType element; struct Node * pFirstChild; struct Node * pNextSibling;}*Tree,*Queue;树的先序递归遍历:void TraverseTree(Tree p){ if(p==NULL) return; cout<<p->element<<endl; TraverseTree(p->pFirstChild); TraverseTree(p->pNextSibli
阅读全文