Sorting Strings : String Sort « String « C Tutorial

Home
C Tutorial
1.Language
2.Data Type
3.String
4.printf scanf
5.Operator
6.Statement
7.Array
8.Function
9.Structure
10.Pointer
11.Memory
12.Preprocessor
13.File
14.Data Structure
15.Search Sort
16.Wide Character String
17.assert.h
18.ctype.h
19.math.h
20.setjmp.h
21.signal.h
22.stdio.h
23.stdlib.h
24.string.h
25.time.h
26.wctype.h
C / ANSI-C
C++
C++ Tutorial
Visual C++ .NET
C Tutorial » String » String Sort 
3.12.2.Sorting Strings
#include <stdio.h>
  #include <string.h>

  /* A Quicksort for strings. */
  void quick_string(char items[][10]int count)
  {
    qs_string(items, 0, count-1);
  }

  int qs_string(char items[][10]int left, int right)
  {
    register 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 < jqs_string(items, left, j);
    if(i < rightqs_string(items, i, right);
  }

  char str[][10"one",
                     "two",
                     "three",
                     "four"
                   };
  int main(void)
  {
    int i;

    quick_string(str, 4);

    for(i=0; i<4; i++printf("%s ", str[i]);

    return 0;
  }
3.12.String Sort
3.12.1.The functional approach to string sorting
3.12.2.Sorting Strings
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.