面试 C 算法 排序
2017-06-27 00:00
232 查看
摘要: 用C语言写出一个将字符串数组进行排序的程序
按降序排序 ,长度越长排最左边,长ॷ...
按降序排序 ,长度越长排最左边,长ॷ...
#include <stdio.h> #include<string.h> main() { char*p_str[8]={"Paris","York","London","Shanghai","Edo","Taipei","Beijing","Singapore"},*temp; int i,j; for(i=0;i<7;i++)//冒泡法排序 { for(j=0;j<7-i;j++) { if(strlen(p_str[j])<strlen(p_str[j+1])) { temp=p_str[j]; p_str[j]=p_str[j+1]; p_str[j+1]=temp; } else if(strlen(p_str[j])==strlen(p_str[j+1])) if(strcmp(p_str[j],p_str[j+1])>1) {temp=p_str[j]; p_str[j]=p_str[j+1]; p_str[j+1]=temp;} } } for(i=0;i<8;i++)//输出字符串 printf("%s ",p_str[i]); printf("\n"); }
相关文章推荐
- 微软等数据结构+算法面试100题(12)--快速排序
- 这是一个我面试某公司的算法题目:对一个字符数组进行排序,根据给定的字符,大于它的,放在数组的左边,小于它的,放在数组的右边,且数组中的元素之间的相对位置要保持不变。
- 【LeetCode-面试算法经典-Java实现】【075-Sort Colors (颜色排序)】
- 笔试面试最常涉及到的12种排序算法(包括插入排序、二分插入排序、希尔排序、选择排序、冒泡排序、鸡尾酒排序、快速排序、堆排序、归并排序、桶排序、计数排序和基数排序)进行了详解。每一种算法都有基本介绍、算
- 【LeetCode-面试算法经典-Java实现】【109-Convert Sorted List to Binary Search Tree(排序链表转换成二叉排序树)】
- C/C++面试之算法系列--1~n无序数组时间复杂度为O(n)排序
- 面试前的准备(java专业 ~学习算法排序以及查找)
- 【LeetCode-面试算法经典-Java实现】【082-Remove Duplicates from Sorted List II(排序链表中删除重复元素II)】
- 【LeetCode-面试算法经典-Java实现】【088-Merge Sorted Array(合并排序数组)】
- 面试常见算法-排序查找算法
- 【LeetCode-面试算法经典-Java实现】【026-Remove Duplicates from Sorted Array(删除排序数组中的重复元素)】
- [面试中的算法]把二元查找树转变成排序的双向链表
- 面试算法(十六)合并两个排序的链表
- 把二元查找树转变成排序的双向链表——精选微软经典的算法面试100题中第一题
- 面试常见算法-排序查找算法
- 微软等数据结构+算法面试100题(43)-- 把二元查找树转变成排序的双向链表
- PHP面试时会考到的算法题之排序
- 面试常见5个算法套装,4个排序+二分查找
- 面试算法——排序
- 面试中的一道排序题算法