主题:[讨论]为什么min模板在visualC++中用不了??我用的是v6.0
[em15]#include<iostream>
#include<cmath>
#include<iomanip>
#include<algorithm>
using namespace std;
template<typename DateType>
void PrintTree(DateType x[],int n);
template<typename DateType>
void PrintOneRow(DateType x[],int numRows,int row,int row_begin,int row_end);
int main()
{
int x[]={87,35,74,67,79,84,76,73,81,32};
make_heap(x,x+10);
PrintTree(x,10);
x[10]=83;
push_heap(x,x+11);
cout<<"after push_heap(83):\n\n";
PrintTree(x,11);
pop_heap(x,x+11);
cout<<"after pop_heap:\n\n";
PrintTree(x,10);
sort_heap(x,x+10);
cout<<"after sort_heap(),array contains:\n\n";
for(int i=0;i<10;i++)
cout<<x[i]<<" ";
cout<<endl;
return 0;
}
template<typename DateType>
void PrintOneRow(DateType x[],int numRows,int row,int row_begin,int row_end)
{
int skip=int(pow(2,numRows-row)-1);
for(int i=row_begin;i<=row_end;i++)
{
cout<<setw(skip)<<" ";
cout<<setw(2)<<x[i];
cout<<setw(skip)<<" ";
}
cout<<endl;
}
template<typename DateType>
void PrintTree(DateType x[],int n)
{
int row_begin=0,row_end=0,rowLen,numRows=int(ceil(log(n)/log(2)));
for(int row=0;row<numRows;row++)
{
PrintOneRow(x,numRows,row,row_begin,row_end);
rowLen=row_end-row_begin+1;
row_begin=row_end+1;
row_end=min(row_end+2*(rowLen),n-1);//提示未定义!
}
}
这个程序运行之后,就会停止工作!!为甚麽呢?希望大家来帮帮忙啊!
#include<cmath>
#include<iomanip>
#include<algorithm>
using namespace std;
template<typename DateType>
void PrintTree(DateType x[],int n);
template<typename DateType>
void PrintOneRow(DateType x[],int numRows,int row,int row_begin,int row_end);
int main()
{
int x[]={87,35,74,67,79,84,76,73,81,32};
make_heap(x,x+10);
PrintTree(x,10);
x[10]=83;
push_heap(x,x+11);
cout<<"after push_heap(83):\n\n";
PrintTree(x,11);
pop_heap(x,x+11);
cout<<"after pop_heap:\n\n";
PrintTree(x,10);
sort_heap(x,x+10);
cout<<"after sort_heap(),array contains:\n\n";
for(int i=0;i<10;i++)
cout<<x[i]<<" ";
cout<<endl;
return 0;
}
template<typename DateType>
void PrintOneRow(DateType x[],int numRows,int row,int row_begin,int row_end)
{
int skip=int(pow(2,numRows-row)-1);
for(int i=row_begin;i<=row_end;i++)
{
cout<<setw(skip)<<" ";
cout<<setw(2)<<x[i];
cout<<setw(skip)<<" ";
}
cout<<endl;
}
template<typename DateType>
void PrintTree(DateType x[],int n)
{
int row_begin=0,row_end=0,rowLen,numRows=int(ceil(log(n)/log(2)));
for(int row=0;row<numRows;row++)
{
PrintOneRow(x,numRows,row,row_begin,row_end);
rowLen=row_end-row_begin+1;
row_begin=row_end+1;
row_end=min(row_end+2*(rowLen),n-1);//提示未定义!
}
}
这个程序运行之后,就会停止工作!!为甚麽呢?希望大家来帮帮忙啊!