IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jun 28, 2004, 10:36:37 AM (22 years ago)
Author:
desonia
Message:

added pslistSort and cooresponding compare functions.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/collections/psList.c

    r1073 r1111  
    11/** @file psList.c
    22 *  @brief Support for doubly linked lists
    3  *  @ingroup DataContainers
     3 *  @ingroup LinkedList
    44 *
    55 *  @author Robert Lupton, Princeton University
    66 *  @author Robert Daniel DeSonia, MHPCC
    77 *
    8  *  @version $Revision: 1.7 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2004-06-23 23:00:15 $
     8 *  @version $Revision: 1.8 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2004-06-28 20:36:37 $
    1010 *
    1111 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    426426    arr->n = list->size;
    427427
    428 
    429428    ptr = list->head;
    430429    n = list->size;
     
    459458    return list;
    460459}
     460
     461
     462psList* psListSort(psList* list, psCompareFcn compare)
     463{
     464    psVector* vector;
     465    if (list == NULL) {
     466        return NULL;
     467    }
     468
     469    // convert to indexable vector for use by qsort.
     470    vector = psListToVector(list);
     471    psFree(list);
     472
     473    qsort(vector->data.V, vector->n, sizeof(void*),
     474          (int(*)(const void *, const void *))compare);
     475
     476    // convert back to linked list
     477    list = psVectorToList(vector);
     478
     479    return list;
     480}
Note: See TracChangeset for help on using the changeset viewer.