摘要: #include <iostream>using namespace std;int parent(int i){ return i/2;}int left(int i){ return 2*i;}int right(int i){ return 2*i+1;}void exchange(int &a,int &b){ int temp; temp=a; a=b; b=temp;}//但就算法来看,heap_size(堆的大小)设为全局变量也许会好一些void max_heapify(int *a,int i,int heap_size){ in... 阅读全文
posted @ 2012-02-17 21:46 Dsp Tian 阅读(442) 评论(0) 推荐(0) 编辑
摘要: #include <iostream>using namespace std;int main(){ int b[]={1,2,3}; int *a; a=(int*)malloc(sizeof(int)*3); memcpy(a,b,sizeof(int)*3); for (int i=0;i<3;i++) cout<<a[i]<<""; cout<<endl; system("pause"); free(a); return 0;} 阅读全文
posted @ 2012-02-17 21:36 Dsp Tian 阅读(493) 评论(0) 推荐(0) 编辑
摘要: #include <iostream>using namespace std;void process(int *a){ a=(int*)realloc(a,sizeof(int)*4); a[3]=3;}int main(){ int *a; a=(int*)malloc(sizeof(int)*3); a[0]=0; a[1]=1; a[2]=2; process(a); for (int i=0;i<4;i++) cout<<a[i]<<""; cout<<endl; system("pause" 阅读全文
posted @ 2012-02-17 21:17 Dsp Tian 阅读(485) 评论(0) 推荐(0) 编辑
摘要: #include <iostream>#include <time.h>#include <stdlib.h>using namespace std;int random(int a,int b){ srand(NULL); return rand()%(b-a)+a;}void exchange(int &a,int &b){ int temp; temp=a; a=b; b=temp;}int main(){ int a[]={1,2,3,4,5,6,7,8,9,10,11,12,13,14}; int length=sizeof(a)/ 阅读全文
posted @ 2012-02-17 19:00 Dsp Tian 阅读(549) 评论(0) 推荐(0) 编辑
摘要: #include <iostream>using namespace std;int parent(int i){ return i/2;}int left(int i){ return 2*i;}int right(int i){ return 2*i+1;}void exchange(int &a,int &b){ int temp; temp=a; a=b; b=temp;}void max_heapify(int *a,int i,int heap_size){ int l=left(i); int r=right(i); i... 阅读全文
posted @ 2012-02-17 18:59 Dsp Tian 阅读(449) 评论(0) 推荐(0) 编辑