zoukankan      html  css  js  c++  java
  • 面试题 33 把数组排成最小的数

    const int g_maxlen = 10;
    char * g_strCombine1 = new char[g_maxlen*2 +1];
    char * g_strCombine2 = new char[g_maxlen*2 +1];
    int compare(const void *str1, const void *str2)
    {
    	strcpy(g_strCombine1, *(const char **)str1);
    	strcat(g_strCombine1, *(const char **)str2);// important
    
    	strcpy(g_strCombine2, *(const char **)str2);
    	strcat(g_strCombine2, *(const char **)str1);
    
    	return strcmp(g_strCombine1, g_strCombine2);
    }
    void printMinNum(int number[], int len)
    {
    	if(number == NULL || len < 1) return ;
    
    	char **strNum = (char **)(new int[len]) ;// 指针的大小是int的大小
    
    	for(int i = 0; i< len ; i++)
    	{
    		strNum[i] = new char[g_maxlen +1];
    		sprintf(strNum[i], "%d", number[i]); // important
    	}
    
    	qsort(strNum,len, sizeof(char*), compare);// important
    
    	for(int i = 0; i < len; ++i)
    		printf("%s", strNum[i]);
    	for(int i = 0; i< len; ++i)
    		delete [] strNum[i];
    	delete [] strNum;
    }
    

      

  • 相关阅读:
    JSONP(处理跨域问题)
    Bootstrap 按钮
    input file 图片上传展示重新上传
    Bootstrap 表单
    Bootstrap 表格
    Bootstrap 代码
    Bootstrap 排版 文本
    bootstrap 栅格calss
    Bootsrap 直接使用
    Bootstrap3和Bootsrap4的区别
  • 原文地址:https://www.cnblogs.com/graph/p/3324331.html
Copyright © 2011-2022 走看看