什么是最简单的方法来对C中的字符数组进行字母排序? [英] What would be the simplest way to alpha sort an array of chars in C?

查看:139
本文介绍了什么是最简单的方法来对C中的字符数组进行字母排序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在寻找一个简单易懂的算法,按字母顺序对C中的字符数组进行排序。

I'm looking for a simple, easy to understand algorithm to alphabetically sort an array of characters in C.

推荐答案

C中的字符具有恰当的数字值,因此您只需将整个字符视为整数。 C标准库包括一个'qsort'函数。使用( man qsort 在类似linux的系统上)。您可能必须将大写字母转换为小写字母以简化操作,但这很简单。如果您想了解快速排序算法(这是您应该了解的一个,因为您实际上会使用它),请参阅维基百科

characters in C have numeric values that happen to be in order, so you just treat your characters like integers. the C standard library includes a 'qsort' function. Use that (man qsort on a linux-like system). You might have to convert upper-case letters to lowercase to simplify things, but that's trivial. If you want to understand the quicksort algorithm (that's the one you should learn, because you'll actually use it), see Wikipedia.

这篇关于什么是最简单的方法来对C中的字符数组进行字母排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆