Sponsored Content
Full Discussion: qsort
Top Forums Programming qsort Post 302082446 by areef4u on Wednesday 2nd of August 2006 08:43:46 AM
Old 08-02-2006
qsort

this is the code in K & R ritchie

void qsort(int v[], int left, int right){
int i, last;
void swap(int v[], int i, int j);

if(left >= right)
return;
swap(v, left, (left + right)/2);
last = left;
for(i = left + 1; i <= right; i++)
if(v[i] < v[left])
swap(v, ++last,i);
swap(v, left, last);
qsort(v , left, last - 1);
qsort(v, last - 1, right);
}

the highlighted portion does not make sense to me at the first go, b'cos it is trying to swap the same element. i find (i & last ) have the same value when swap is called in the for loop for the first time, plz explain....

thanks in advance
 

We Also Found This Discussion For You

1. Programming

Qsort Error

I am looking at a small C program that uses qsort to sort an array of strings and an error occurs when it passes qsort a function to compare integers instead of strings. Why can't the compiler catch this? And what would happen if I was using qsort to sort integers and accidentally pass the string... (3 Replies)
Discussion started by: totoro125
3 Replies
OPERATOR(7)                                                  Linux Programmer's Manual                                                 OPERATOR(7)

NAME
operator - C operator precedence and order of evaluation DESCRIPTION
This manual page lists C operators and their precedence in evaluation. Operator Associativity () [] -> . left to right ! ~ ++ -- + - (type) * & sizeof right to left * / % left to right + - left to right << >> left to right < <= > >= left to right == != left to right & left to right ^ left to right | left to right && left to right || left to right ?: right to left = += -= *= /= %= <<= >>= &= ^= |= right to left , left to right COLOPHON
This page is part of release 4.15 of the Linux man-pages project. A description of the project, information about reporting bugs, and the latest version of this page, can be found at https://www.kernel.org/doc/man-pages/. Linux 2011-09-09 OPERATOR(7)
All times are GMT -4. The time now is 09:26 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy