Advertisement
Fede

Untitled

Dec 22nd, 2014
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. void sequential_sort_2(int * V, int N, int * perm){
  2.  int max, min, count, start=0, end=N-1;
  3.  
  4.  if(N<=0)
  5.   return
  6.  else if(N==1){
  7.   perm[0] = 0;
  8.   return;
  9.  else {
  10.  
  11.   for(count=0, count<N, count++)
  12.    perm[count] = count;
  13.  
  14.   while(start<end){
  15.    for(min=start, max = start, count=start+1; count<end; count++){
  16.  
  17.     if(V[perm[count]] > V[perm[count+1]{
  18.      if(V[perm[count]] > V[perm[max])
  19.       max = count;
  20.      if(V[perm[count+1]] < V[perm[min])
  21.       min = count+1;
  22.     }
  23.     else{
  24.      if(V[perm[count]] < V[perm[min]])
  25.       min = count;
  26.      if(V[perm[count+1] > V[per[max]]
  27.       max = count+1;
  28.     }
  29.    }
  30.    if(count == end){
  31.     if(V[perm[count]] < V[perm[min]])
  32.       min = count;
  33.    }
  34.    else
  35.     if(V[perm[count]] > V[perm[max])
  36.      max = count;
  37.    
  38.    swap(perm, min, start);
  39.    swap)perm, max, end);
  40.    
  41.    start++;
  42.    end--;
  43.   }
  44.  }
  45. }
  46.  
  47. void swap(int * A, int i1, int i2){
  48.  int tmp = A[i1];
  49.  A[i1] = A[i2];
  50.  A[i2] = tmp;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement