Sponsored Content
Full Discussion: qsort
Top Forums Programming qsort Post 302082686 by Perderabo on Thursday 3rd of August 2006 01:30:19 AM
Old 08-03-2006
It is possible for a if statement to be false. Do you think that if statements always must be true? Doesn't work like that.

In the worst possible case, where v[i] is always less than v[left], the routine will march along always swapping nothing. As a side effect of the (no-op) swap last is incremented. We need that side effect so the swap is performed regardless of whether it's really swapping.

But suppose that the worst possible case does not arise. If the routine should ever encounter even a single case where v[i] is not less than v[left], last and i would move out of sync. This would last for the rest of the loop, once out of sync, they could never sync up again.

If this bums you out too much, put a test in the swap routine to inhibit the swap if you are not really swapping. But now you are performing a test for every swap. The superfluous test will slow you down if it rarely inhibits a swap. But if it winds up inhibiting most of them, it might be worth it. It's your call...how pessimistic are you? Smilie
 

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
SWAPON(8)						      System Manager's Manual							 SWAPON(8)

NAME
swapon - specify additional device for paging and swapping SYNOPSIS
swapon -a swapon name ... DESCRIPTION
Swapon is used to specify additional devices on which paging and swapping are to take place. The system begins by swapping and paging on only a single device so that only one disk is required at bootstrap time. Calls to swapon normally occur in the system multi-user initial- ization file /etc/rc making all swap devices available, so that the paging and swapping activity is interleaved across several devices. Normally, the -a argument is given, causing all devices marked as ``sw'' swap devices in /etc/fstab to be made available. The second form gives individual block devices as given in the system swap configuration table. The call makes only this space available to the system for swap allocation. SEE ALSO
swapon(2), init(8) FILES
/dev/[ru][pk]?b normal paging devices BUGS
There is no way to stop paging and swapping on a device. It is therefore not possible to make use of devices which may be dismounted dur- ing system operation. swapon is not implemented in 2.11BSD. 4th Berkeley Distribution November 17, 1996 SWAPON(8)
All times are GMT -4. The time now is 12:06 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy