随笔分类 - Algorithms
摘要:/** * Definition for a binary tree node. * function TreeNode(val) { * this.val = val; * this.left = this.right = null; * } *//** * @param {Tre...
阅读全文
摘要:/** * 题意:将0挪到末尾,并且不改数组中原有元素的顺序 * 解析:找到0元素,然后寻找其后面非0的元素,进行交换位置 * @param {number[]} nums * @return {void} Do not return anything, modify nums in-place i...
阅读全文
摘要:/** *题意:判断两棵二叉树 * Definition for a binary tree node. * function TreeNode(val) { * this.val = val; * this.left = this.right = null; * } *//** ...
阅读全文
摘要:#include#include#includeusing namespace std;struct ListNode{ int data; ListNode *lchild,*rchild;};ListNode* Createbst(){ int data; scanf("...
阅读全文
摘要:例如“abc”输出a,b,c,ab,ac,bc,abc#includevoid DFS(char str[],char ss[],int pos,int cnt,int n){ if(n==pos) { ss[cnt]='\0'; if(cnt!=0) pri...
阅读全文
摘要:#includevoid ShellSort(int array[],int length){ int i,j,h,temp; for(h=length/2;h>0;h=h/2) { for(i=h;i=0;j-=h) { ...
阅读全文
摘要:#includevoid AdjustMinHeap(int *a,int pos,int len){ int temp,child; for(temp=a[pos];pos*2+1=0;i--) AdjustMinHeap(array,i,len-1); for(i=le...
阅读全文
摘要:#include#includeusing namespace std;//日期函数int days[12]={31,28,31,30,31,30,31,31,30,31,30,31};struct date{ int year,month,day;};//判闰年inline int leap(in...
阅读全文
摘要:struct ListNode{ int data; ListNode *lchild,*rchild;};void CreateBSTree(ListNode *B2_root,ListNode *BSTree_root){ if(BSTree_root==NULL) ...
阅读全文
摘要:#include#include#includeusing namespace std;void GetNext(char *str,int next[]){ int j,k; j=0;k=-1;next[0]=-1; while(str[j]!='\0') { ...
阅读全文
摘要:中缀表达式“9+(3-1)*3+10/2”转化为后缀表达式“9 3 1-3*+ 10 2/+”中缀表达式转后缀表达式的方法:1.遇到操作数:直接输出(添加到后缀表达式中)2.栈为空时,遇到运算符,直接入栈3.遇到左括号:将其入栈4.遇到右括号:执行出栈操作,并将出栈的元素输出,直到弹出栈的是左括号,...
阅读全文
摘要:#includevoid InsertSort(int n,int a[]){ int j; for(int i=0;i=0;j--) { if(a[j]>tmp) { a[j+1]=a[j]; ...
阅读全文
摘要:#includevoid SelectSort(int n,int a[]){ for(int i=0; i<n; i++) { int MIN=a[i]; int k=i; for(int j=i+1; j<n; j++) { ...
阅读全文
摘要:#includevoid BubbleSort(int n,int a[]){ for(int i=0;ia[j+1]) { int tmp=a[j]; a[j]=a[j+1]; a...
阅读全文
摘要:#includevoid MergeArray(int first,int mid,int last,int a[]){ int k=0; int i=first,j=mid+1; int n=mid,m=last; int c[100]; while(i<=n && ...
阅读全文
摘要:#include#includeusing namespace std;typedef int ElemType;typedef struct Node{ ElemType data; struct Node* next;}*LinkList,Node;LinkList LinkList...
阅读全文
摘要:#include#include#includetypedef int Item;typedef struct node* PNode;typedef struct node{ Item data; PNode next;}Node;typedef struct{ PNode fr...
阅读全文
摘要:学习地址: http://hi.baidu.com/vfxupdpaipbcpuq/item/dce4e6f8a8c45f13d7ff8cda
阅读全文
摘要:void eular(){ memset(vis,0,sizeof(vis)); vis[0]=vis[1]=1; for(i=2;i*i 1) res = res / x * (x - 1); return res;}
阅读全文
摘要:#include#include#include#includeusing namespace std;const int MN=2011;vectoredge[MN];vectorSCC[MN];stacks;int low[MN],dfn[MN];int instack[MN],stap[MN]...
阅读全文