A Quicksort for strings : Quick sort « Data Structure Algorithm « C / ANSI-C

Home
C / ANSI-C
1.assert.h
2.Console
3.ctype.h
4.Data Structure Algorithm
5.Data Type
6.Development
7.File
8.Function
9.Language Basics
10.Macro Preprocessor
11.Math
12.math.h
13.Memory
14.Pointer
15.setjmp.h
16.signal.h
17.Small Application
18.stdio.h
19.stdlib.h
20.String
21.string.h
22.Structure
23.time.h
24.wctype.h
C Tutorial
C++
C++ Tutorial
Visual C++ .NET
C / ANSI-C » Data Structure Algorithm » Quick sortScreenshots 
A Quicksort for strings
A Quicksort for strings

#include <stdio.h>
#include <string.h>

void quickSortMain(char items[][10]int count);
void quickSort(char items[][10]int left, int right);

int main(void)
{
  int i;
  char str[][10"this","is","a","test"};

  quickSortMain(str, 4);

  for(i=0; i<4; i++) {
     printf("%s ", str[i]);
  }
  return 0;
}
void quickSortMain(char items[][10]int count)
{
  quickSort(items, 0, count-1);
}

void quickSort(char items[][10]int left, int right)
{
  int i, j;
  char *x;
  char temp[10];

  i = left;
  j = right;
  x = items[(left+right)/2];

  do {
    while((strcmp(items[i],x0&& (i < right)) {
       i++;
    }
    while((strcmp(items[j],x0&& (j > left)) {
        j--;
    }
    if(i <= j) {
      strcpy(temp, items[i]);
      strcpy(items[i], items[j]);
      strcpy(items[j], temp);
      i++;
      j--;
   }
  while(i <= j);

  if(left < j) {
     quickSort(items, left, j);
  }
  if(i < right) {
     quickSort(items, i, right);
  }
}

           
       
Related examples in the same category
1.The Quicksort
2.A Quicksort for filesA Quicksort for files
3.How to use sysmtem quick sortHow to use sysmtem quick sort
4.Sort: quicksort: how to use qsort
5.Quick sort on two dimensional string arrayQuick sort on two dimensional string array
6.Use the system quick sort
7.A Quicksort for structures of type address
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.