Showing posts with label Sorting. Show all posts
Showing posts with label Sorting. Show all posts

Wednesday, 17 October 2012

C Program to sort filenames in a directory?

How do you sort filenames in a directory?


The below example shows how to get a list of files one at a time. The example uses the _dos_findfirst() and _dos_findnext() functions to walk through the directory structure. As each filename is found, it is printed to the screen.

When you are sorting the filenames in a directory, the one-at- a-time approach does not work. You need some way to store the filenames and then sort them when all filenames have been

Monday, 23 January 2012

The Radix Sort

The radix sort shown below takes a list of integers and puts each element on a smaller list, depending on the value of its least significant byte. Then the small lists are concatenated, and the process is repeated for each more significant byte until the list is sorted. The radix sort is simpler to implement on fixed-length data such as ints, but it is illustrated here using strings.

Two functions perform the radix sort. The function radixSort() performs one pass through the data, performing a partial sort. Line

Tuesday, 3 January 2012

What is the easiest sorting method to use?

The answer is the standard library function qsort(). It’s the easiest sort by far for several reasons:

It is already written.
It is already debugged.
It has been optimized as much as possible (usually).


The algorithm used by qsort() is generally the quick sort algorithm, developed by C. A. R. Hoare in 1962.

Here is the prototype for qsort():

void qsort(void *buf, size_t num, size_t size,

int (*comp)(const void *ele1, const void *ele2));


The qsort() function takes a pointer to an array of user-defined data (buf). The array has num elements in it, and each element is size bytes long. Decisions about sort order are made by calling comp,

Monday, 19 December 2011

Brief idea about Sorting

Five basic kinds of sorting algorithms are available to the programmer:

  • Insertion sorts

  • Exchange sorts

  • Selection sorts

  • Merge sorts

  • Distribution sorts


An easy way to visualize how each sorting algorithm works is to think about how to sort a shuffled deck of cards lying on the table using each method. The cards are to be sorted by suit (clubs, diamonds, hearts, and spades) as well as by rank (2 through ace). You might have seen some of these algorithms in action at your last bridge game.

In an insertion sort, you pick up the cards one at a time, starting with the top card in the pile, and insert them into the correct position in

Friday, 28 October 2011

Sorting is not possible by using which of the following methods?


  1. Insertion

  2. Selection

  3. Exchange

  4. Deletion


Ans: Deletion

Using insertion we can perform insertion sort, using selection we can perform selection sort, using exchange we can perform the bubble sort (and other similar sorting methods). But no sorting method can be done just using deletion.