Everything2
Near Matches
Ignore Exact
Full Text
Everything2

Sorting Algorithms : Rank Sort

created by SoberSephiroth

(idea) by SoberSephiroth (4.8 y) (print)   ?   (I like it!) Wed Sep 13 2000 at 17:29:44

The rank sort is another method of sorting an array. Since its time complexity is O(nē), it is not highly recommended for use, but is very intuitive and easy to understand. To perform a rank sort, here is generic C++:

template <class T>
void Rank(T a[], int n, int r[])
{

for (int i=0;i<n;i++)
r[i]=0; //initialize rank array
for(int i=1;i<n;i++)
for(int j=0;j<i;j++)
if(a[j]<=a[i]) r[i]++;
else r[j]++;
}

template <class T>
void Rearrange(T a[],int n,int r[])
{

T *u=new T[n+1]
for (int i=0;i<n;i++)
u[r[i]]=a[i]
for(int i =0;i<n;i++)
a[i]=u[i]
delete []u;
}

As you can see, the first function ranks the passed array and tells the second function which order to place the objects into. In order for the code to work properly, the comparison operators must be overloaded for the respective class T.


printable version
chaos

Sorting is O(n log n) Sorting Algorithms graph traversal Zen Sort
Rank Time complexity rack and stack algorithm
Deadlock binary search Evil
Y'know, if you log in, you can write something here, or contact authors directly on the site. Create a New User if you don't already have an account.
  Epicenter
Login
Password

password reminder
register

Everything2 Help

Cool Staff Picks
Little presents from the Node Fairy:
eBay
Erotic nodes
Jello Biafra's Platform for Year 2000 Green Party
It kills me to watch them go
Full Moon Rituals
Plastic Birth
beekeeping
Kandahar
occidentalism
How to make a crossword puzzle
God slipped away quietly, during third period physics class
Extinction
bestiary
New Writeups
Clarke
Multiculturalism(idea)
aneurin
Earl of Landaff(person)
Heitah
Pseudocide(idea)
XWiz
Google Knol(lede)
Mythi
July 24, 2008(personal)
locke baron
The fall of Earth(fiction)
BookReader
Fear the Cold(dream)
Pavlovna
Kathleen MacInnes(person)
stainedglass
1(fiction)
kalen
Three "T"s(idea)
octillion369
Undead(idea)
archiewood
Ico(fiction)
Heisenberg
Why I love Everything2(log)
octillion369
Death Knight(person)
XWiz
Are you hoping for a miracle?(review)
Everything 2 is brought to you by the letter C and The Everything Development Company