Commit 9f47569a authored by rswindell's avatar rswindell
Browse files

Added str_list sorting functions.

parent d8b66f2d
......@@ -35,7 +35,7 @@
* Note: If this box doesn't appear square, then you need to fix your tabs. *
****************************************************************************/
#include <stdlib.h> /* malloc */
#include <stdlib.h> /* malloc and qsort */
#include "str_list.h"
str_list_t strListAlloc()
......@@ -85,6 +85,46 @@ str_list_t strListAdd(str_list_t* list, char* str)
return strListAddAt(list,str,strListCount(*list));
}
static int strListCompareAlpha(const void *arg1, const void *arg2)
{
return stricmp(*(char**)arg1, *(char**)arg2);
}
static int strListCompareAlphaReverse(const void *arg1, const void *arg2)
{
return stricmp(*(char**)arg2, *(char**)arg1);
}
static int strListCompareAlphaCase(const void *arg1, const void *arg2)
{
return strcmp(*(char**)arg1, *(char**)arg2);
}
static int strListCompareAlphaCaseReverse(const void *arg1, const void *arg2)
{
return strcmp(*(char**)arg2, *(char**)arg1);
}
void strListSortAlpha(str_list_t list)
{
qsort(list,strListCount(list),sizeof(char*),strListCompareAlpha);
}
void strListSortAlphaReverse(str_list_t list)
{
qsort(list,strListCount(list),sizeof(char*),strListCompareAlphaReverse);
}
void strListSortAlphaCase(str_list_t list)
{
qsort(list,strListCount(list),sizeof(char*),strListCompareAlphaCase);
}
void strListSortAlphaCaseReverse(str_list_t list)
{
qsort(list,strListCount(list),sizeof(char*),strListCompareAlphaCaseReverse);
}
void strListFree(str_list_t* list)
{
size_t i;
......
......@@ -62,6 +62,11 @@ str_list_t strListAddAt(str_list_t* list, char* str, size_t index);
/* Count the number of strings in the list and returns the count */
size_t strListCount(str_list_t list);
void strListSortAlpha(str_list_t list);
void strListSortAlphaReverse(str_list_t list);
void strListSortAlphaCase(str_list_t list);
void strListSortAlphaCaseReverse(str_list_t list);
#if defined(__cplusplus)
}
#endif
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment