C#数组的排序(正序逆序)
C#数组的排序(正序逆序)
这种排序 超级简单的 !
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text; namespace ConsoleApplication4
{
class Program
{
static void Main(string[] args)
{ string[] str = { "d","h","a","c","g","t","e","u","b"}; var lowtohigh = from p in str orderby p select p; //linq
str = lowtohigh.ToArray();
foreach (var item in str)
{
Console.WriteLine("正序排列" + item);//正序排列
}
//=================================================
for (int i = 0; i < str.Length/2;i ++ )
{
string temp=str[i]; //新建一个变量相互交换
str[i]=str[str.Length-i-1];
str[str.Length - i - 1] = temp;//相互交换
}
foreach (var newstr in str)
{
Console.WriteLine("逆序排列:"+newstr);
}
Console.WriteLine("===================================");
//###############################################
int[] num = { 5, 78, 9, 1, 8, 4, 2, 88, 3 };
var lowtohigh1 = from p in num orderby p select p;
num = lowtohigh1.ToArray();
foreach (var num1 in num)
{
Console.WriteLine(num1);//正序排列
} for (int i = 0; i < num.Length / 2;i++ )
{
int temp =num[i]; //新建一个变量相互交换
num[i] = num[num.Length - i - 1];
num [num.Length - i - 1] = temp;//相互交换
}
foreach (var newnum in num)
{
Console.WriteLine("逆序排列:" + newnum);
}
Console.WriteLine("==================================="); }
}
}
结果:

C#数组的排序(正序逆序)的更多相关文章
- PHP数组foreach循环如何实现逆序访问?
PHP数组foreach循环如何实现逆序访问? 一.总结 1.array_reverse($array) :foreach(array_reverse($array) as $key=>$val ...
- oracle 正序 逆序 排序查询
正序:从小到大 order by t.id asc 逆序:从大到小 order by t.id desc
- C#SortedList排序列表怎么样逆序输出
C#分别在集合库和泛型库中有共2套SortedList 以较新的泛型库为例,SortedList<int, string> l = new SortedList<int, strin ...
- java 将一个数组中的值按逆序重新存放,例如,原来顺序为:9,5,7,4,8,要求改为:8,4,7, 5,9。
public class Test3 { public static void main(String[] args) { int[] grade = {87,88,89,98,78}; int m; ...
- Java实现蓝桥杯VIP算法训练 数组逆序排列
试题 算法训练 数组逆序排列 资源限制 时间限制:1.0s 内存限制:256.0MB 问题描述 编写一个程序,读入一组整数(不超过20个),并把它们保存在一个整型数组中.当用户输入0时,表示输入结束. ...
- Openjudge计算概论——数组逆序重放【递归练习】
/*===================================== 数组逆序重放 总时间限制:1000ms 内存限制:65536kB 描述 将一个数组中的值按逆序重新存放. 例如,原来的顺 ...
- c - 逆序/正序输出每位.
#include <stdio.h> #include <math.h> /* 判断一个正整数的位数,并按正序,逆序输出他们的位. */ int invert(int); vo ...
- 计算概论(A)/基础编程练习2(8题)/6:数组逆序重放
#include<stdio.h> int main() { // 输入n个整数 ; scanf("%d", &n); // 循环读入元素 while(scan ...
- OpenJudge计算概论-数组逆序重放
/*=============================================================== 数组逆序重放 总时间限制: 1000ms 内存限制: 65536kB ...
随机推荐
- 浅谈thinkphp中将字符串转换成json数组的方法
这是一部分代码: $client = M("Client");$data = $client->where('user_id ='.$user_id)->select( ...
- c++之路进阶——hdu3507(Print Article)
参考博文:http://www.cnblogs.com/ka200812/archive/2012/08/03/2621345.html//讲的真的很好,有个小错误,博客里的num全为sum,像我这种 ...
- HDU 4900 NO ACM NO LIFE(概率+枚举+搜索)(2014 Multi-University Training Contest 4)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4900 Problem Description There is an old country and ...
- app_field.clear_dependent_fields
可以调用APP_FIELD.clear_dependent_fields和APP_FIELD.set_dependent_field来将两个(或多个)Item建立关联,当一个为空时,另一个不可录入,反 ...
- SQL优化SQL tuning
1. 索引不合适,走主键进行了key lookup查找 说明索引没有覆盖到where条件 或者 orderby 或者 group by的列
- UBoot讲解和实践-----------讲解(一)
Boot Loader之ARM Uboot移植 阶段一 理论篇 1.boot loader需要完成的任务: 1>设计程序的入口地址 2&g ...
- [php]表单和验证
<?php /* 表单的作用: 通过表单 发布和收集 信息. 对html表单进行编码 只是有效接受用户输入的必要操作的(一部分), 必须由[服务器端]组件来处理 一 标头函数(header()) ...
- 【海岛帝国系列赛】No.6 海岛帝国:战争前线
50234237海岛帝国:战争前线 [试题描述] 总指挥官WHT出神入化的计谋虽然大有用武之地,但是聪明的恐怖分子们采取了城市核武器防御系统,可以有效地抵制WHT的炸弹.YSF对此头痛不已,因此 召开 ...
- 161121、hibernate导致数据出错的两个地方
一.在查询出来的对象上直接设置属性(该属性配置了可以持久化,如果不是可持久化的就没有关系). 出错的代码:(查询用的不好也会导致数据更新哦) Pagination pagination = group ...
- makefile 中 $@ $^ %< 使用【转】
转自:http://blog.csdn.net/kesaihao862/article/details/7332528 这篇文章介绍在LINUX下进行C语言编程所需要的基础知识.在这篇文章当中,我们将 ...