字符串去重并排序

时间:2014-05-18 18:24:36   收藏:0   阅读:221

1. 一个简单的去除字符串中字符重复,并排序的算法


void remove_replace (char *str) 
{
    /* pos 是构造新字符串时的当前位置 */
    int     i, pos = 0;
    unsigned char    buf[256] = {0};

    for (i = 0; str[i]; i++) {

        if (1 == (buf[str[i]] += 1))
            str[pos++] = str[i];
    }
    memset (str+pos, 0, strlen (str));
}


字符串去重并排序,布布扣,bubuko.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!