test
来源:互联网 发布:4个千兆sfp端口 编辑:程序博客网 时间:2024/05/19 18:48
// test.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;
//big root heap
void MaxHeapify(int *arrayA,int i, int length)
{
int max=0;
while (i<length)
{
max=i;
if(arrayA[i] < arrayA[2*i+1] && (2*i+1 < length))
{
max=2*i+1;
}
if(arrayA[max]<arrayA[2*i+2] && (2*i+2 < length))
{
max=2*i+2;
}
if(max != i)
{
int temp = arrayA[i];
arrayA[i]=arrayA[max];
arrayA[max]=temp;
i=max;
}
else
{
break;
}
}
}
void BuildHeap(int * array, int size)
{
int i=size/2;
while(i>0)
{
MaxHeapify(array,i, size);
i--;
}
}
void HeapSort(int *array, int m)
{
BuildHeap(array, m);
int i=(m+1)/2;
int j=0;
while( j < m-i)
{
int temp=array[m-j];
array[m-j]=array[0];
array[0]=temp;
MaxHeapify(array,0,m-j);
j++;
cout<<"the value is:"<<array[0];
}
}
int Partition(int *array, int m, int n)
{
int pilot = array[n];
int j=m-1;
int i=m;
int temp=0;
while(i<n)
{
if(array[i]<pilot)
{
temp=array[i];
array[i]=array[j+1];
array[j+1]=temp;
j++;
}
else
{
}
i++;
}
temp=array[n];
array[n] = array[j+1];
array[j+1]=temp;
return j+1;
}
void QuickSort(int *array, int m, int n)
{
if(m<n)
{
int k = Partition(array, m, n);
QuickSort(array,m,k-1);
QuickSort(array,k+1,n);
}
return;
}
int _tmain(int argc, _TCHAR* argv[])
{
int arrray[10]={2,13,3,7,4,5,10,8,1,6};
HeapSort(arrray,9);
string test("hello world!");
cout<<"hello world!"<<test<<endl;
return 0;
}
- test
- test
- test
- test
- test
- test
- test
- Test
- test
- Test
- test
- test
- test
- test
- test
- test
- test
- Test
- 整数划分hdu 4651,hdu4658
- wordpress主题常用函数(二)
- java double 类型的怪现象
- 转载:CentOS如何给Firefox安装Flash插件
- delphi开发实例:保存字体设置的方法
- test
- 根据资源路径加载ZIP压缩包中指定的资源
- 填报表
- 常用个人密码管理软件
- 黑马程序员_自己写的DbHelper类库
- 常用js备用
- 分类:决策树—— Records of Questions
- response.write()不执行的解决办法
- Tomcat中的配置DBCP