Sponsored Content
Top Forums Programming How to invert order in QuickSort Post 302421825 by rafazz on Sunday 16th of May 2010 02:06:01 PM
Old 05-16-2010
How to invert order in QuickSort

Hello! Iam trying to reverse my order of quicksort in C from asc order (1-99) that is the original way of the algoritm, to descending (99-1). I've tried so many ways that iam a kind of lost now!:s

The original quicksort is:
Code:
void swap(int* a, int* B) {
  int tmp;
  tmp = *a;
  *a = *b;
  *b = tmp;
}
 
int partition(int vec[], int left, int right) {
  int i, j;
 
  i = left;
  for (j = left + 1; j <= right; ++j) {
    if (vec[j] < vec[left]) {
      ++i;
      swap(&vec[i], &vec[j]);
    }
  }
  swap(&vec[left], &vec[i]);
 
  return i;
}
 
void quickSort(int vec[], int left, int right) {
  int r;
 
  if (right > left) {
    r = partition(vec, left, right);
    quickSort(vec, left, r - 1);
    quickSort(vec, r + 1, right);
  }
}

Thanks for all! Good work!

Last edited by rafazz; 05-16-2010 at 03:21 PM.. Reason: forget to mention the language
 

10 More Discussions You Might Find Interesting

1. AIX

Where to Order 5.1L Cds

Anyone know where you can purchase a 5.1 cd set? IBM no longer ships this out and do not have a set. I have a burned copy, but would be nice to have the originals. I'd like to send my copies offsite for DR once i get an original set. Thanks! (2 Replies)
Discussion started by: slacker
2 Replies

2. UNIX for Dummies Questions & Answers

Order sorting

How do you sort text in order using sed? :confused: For example 01 B D A C to 01 ABCD (3 Replies)
Discussion started by: evoGage
3 Replies

3. Shell Programming and Scripting

Printing the invert of the last field of awk

in csh set x = "/home/usr/dir1/file1" if i do: echo $x | awk -F\/ '{print $NF}' will result to: "file1" how do i invert the output to: "/home/usr/dir1" :confused: (2 Replies)
Discussion started by: jehrome_rando
2 Replies

4. Shell Programming and Scripting

Invert Matrix of Data - Perl

I have columnar data in arrays perl, Example - @a = (1,2,3); @array1 = (A,B,C); @array2 = (D,E,F); @array3 = (I,R,T); I want the data to be formatted and printed as 1 A D I 2 B E F 3 C F T and so on... (8 Replies)
Discussion started by: dinjo_jo
8 Replies

5. Shell Programming and Scripting

Change order

Good evening I have a file as below and want to change the order, as in the second column, sed awk Pearl Thanks aaaaaaaaaa bbbbbbbbb cccccccc aaaaaaaaaa bbbbbbbbb cccccccc aaaaaaaaaa cccccccc bbbbbbbbb aaaaaaaaaa cccccccc bbbbbbbbb (8 Replies)
Discussion started by: Novice-
8 Replies

6. Ubuntu

Boot order?

Hi I have Ubuntu 10.10 installed. I want to change boot order. Can anyone tell where is menu.lst file located. I searched it but didn't get it. Please tell me what file I need to edit for same? (3 Replies)
Discussion started by: nixhead
3 Replies

7. Shell Programming and Scripting

Column not in order

Hi, I was trying to have an output as below : 1 | 2 | 3 aaa | bbb | ccc | ccc | ccc ... (2 Replies)
Discussion started by: scottralf
2 Replies

8. Shell Programming and Scripting

Using grep or something similar to invert search.

Hi guys, I have a script in which it simply do a grep of strings for the var/adm/messages file: NEWDATE=`TZ=GMT+1 date +%b" "%d" "%H` getalarm1=`grep "sent to primary BE" /var/adm/messages* | grep "$NEWDATE" | wc -l` getalarm2=`grep "CC-Request-Type 3 received in state Idle"... (5 Replies)
Discussion started by: matcam79
5 Replies

9. UNIX for Dummies Questions & Answers

Increasing order

Hi , I have around 1000000 odd lines in a file in random order. The file looks like this: >string102 >string10437183 >string514 >string10435771 >string10437259 >string1049931 >string1342 I want to arrange it in increasing order: >string102 >string514 >string1342... (3 Replies)
Discussion started by: qwerty193
3 Replies

10. UNIX for Beginners Questions & Answers

Order by 1

select to_char(cre_on, 'ddmm hh24'), proc_flg, count(*) from ib_prd.tb_ibmh_msg_log where message_type = 'DECHECK_OUT' and cre_on > to_date('27/08/2016 00:00:00', 'dd/MM/yyyy hh24:mi:ss') group by to_char(cre_on, 'ddmm hh24'), proc_flg order by 1; 1) what does order by 1 means 2) group by... (1 Reply)
Discussion started by: houmingc
1 Replies
dia(2rheolef)							    rheolef-6.1 						     dia(2rheolef)

NAME
dia - diagonal matrix DESCRIPTION
The class implements a diagonal matrix. A declaration whithout any parametrers correspond to a null size matrix: dia<Float> d; The constructor can be invocated whith a ownership parameter (see distributor(2)): dia<Float> d(ownership); or an initialiser, either a vector (see vec(2)): dia<Float> d(v); or a csr matrix (see csr(2)): dia<Float> d(a); The conversion from dia to vec or csr is explicit. When a diagonal matrix is constructed from a csr matrix, the definition of the diagonal of matrix is @emph{always} a vector of size row_ownership which contains the elements in rows 1 to nrow of the matrix that are contained in the diagonal. If the diagonal element falls outside the matrix, i.e. ncol < nrow then it is defined as a zero entry. PRECONDITIONER INTERFACE
The class presents a preconditioner interface, as the solver(2), so that it can be used as preconditioner to the iterative solvers suite (see pcg(4)). IMPLEMENTATION
template<class T, class M = rheo_default_memory_model> class dia : public vec<T,M> { public: // typedefs: typedef typename vec<T,M>::size_type size_type; typedef typename vec<T,M>::iterator iterator; typedef typename vec<T,M>::const_iterator const_iterator; // allocators/deallocators: explicit dia (const distributor& ownership = distributor(), const T& init_val = std::numeric_limits<T>::max()); explicit dia (const vec<T,M>& u); explicit dia (const csr<T,M>& a); dia<T,M>& operator= (const T& lambda); // preconditionner interface: solves d*x=b vec<T,M> solve (const vec<T,M>& b) const; vec<T,M> trans_solve (const vec<T,M>& b) const; }; template <class T, class M> dia<T,M> operator/ (const T& lambda, const dia<T,M>& d); template <class T, class M> vec<T,M> operator* (const dia<T,M>& d, const vec<T,M>& x); SEE ALSO
distributor(2), vec(2), csr(2), solver(2), pcg(4) rheolef-6.1 rheolef-6.1 dia(2rheolef)
All times are GMT -4. The time now is 09:37 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy