www.pudn.com > permrank.rar > permrank.cpp
#include#include using namespace std; struct Object { int value; int index; operator int(){ return value;} bool operator>(const Object& oo){ return value>oo.value;} bool operator<(const Object& oo){ return value >n; int *element=new int[n]; Object *ob=new Object[n]; for (i=0;i >element[i]; ob[i].value=element[i]; ob[i].index=i; } int *less=new int[n];//less[i] stores numbers of less than element[i] from 0 to i-1 for(i=0;i =0;i--) fout< s; s.push(ob[n-1]); int min=n+1,i=n-2; while(i>=0){//O(n),可以使用两重for循环简单实现O(n2) if(ob[i]>s.top()) { s.push(ob[i]);i--;} else{ while(!s.empty()&&ob[i] ob[i].index+1;k--)//冒泡排序, for(j=ob[i].index+1;j a[j+1]) swap(a[j],a[j+1]); return true; } } /*long Find_index(int a[],int less[],int n){ long num=0; for(int i=0;i